原文地址:http://www.cprogramming.com/whyc.html
為什么學(xué)習(xí)C
Why Learn C?
現(xiàn)在大家在用的計(jì)算機(jī)語言的數(shù)量多得可怕。從高級(jí)語言(比如VB)到低級(jí)語言,有非常多的選擇(Perl,Ruby和Python語言,對(duì)于很多任務(wù)的實(shí)現(xiàn)都是不錯(cuò)的選擇)。Java已經(jīng)成為了一些項(xiàng)目非常受歡迎的語言,某種程度上也是因?yàn)樗鼡碛写罅康腁PI和虛擬機(jī)機(jī)制提供了比較好的安全性。(內(nèi)存垃圾收集器也是一個(gè)非常不錯(cuò)的功能,可以使得程序員更有效率。)
There are an awful lot of programming languages available right now -- everything from the extremely high level (such as Visual Basic) to the low level power of assembly, and a good variety of specialized options in between (
Perl,
Ruby, and
Python are good choices for many tasks). Java has also become quite the hot programming language for some tasks, in part because of its large API and in part because the virtual machine provides some elements of security. (Garbage collection is another nice feature and can make programmers much more efficient.)
然而,學(xué)習(xí)c語言編程,也有很多很好的理由。第一,歷史悠久:C語言已有30多年的歷史了(譯者注:到現(xiàn)在已有近40年了),能找到大量的有效的源代碼。這也意味著有很多可以學(xué)習(xí)的例子,也有很多是可以直接拿來用的代碼。而且,語言的很多問題都已經(jīng)說明的很清楚--它可以更好的理解,并且你可以找到很多很不錯(cuò)的教程。另外,對(duì)于C,你可以獲得很多你能理解的看法和見解。
Nevertheless, there are some good reasons to learn to program in C. First, age has its advantages: C has been around for 30 years, and there is a ton of source code available. This means there's a lot to learn from, and a lot to use. Moreover, many of the issues with the language have been clearly elucidated -- it's well understood, and you can find a lot of
tutorials available. Plus, with C, you get lots of strong
opinions mixed with insights that you can understand.
由于歷史的原因,C做為Unix的一個(gè)系統(tǒng)編程語言,C已經(jīng)成為了一門通用的編程語言。有時(shí)候用C語言來表達(dá)一些編程上的想法,大部分人都會(huì)感覺到比較舒服。
As a result of its age and its use as the language of system programming for Unix, C has become something of the
lingua franca of programming. C is a great language for expressing common ideas in programming in a way that most people are comfortable with. Moreover, a lot of the principles used in C -- for instance, argc and argv for command line parameters, as well as loop constructs and variable types -- will show up in a lot of other languages you learn so you'll be able to talk to people even if they don't know C in a way that's common to both of you.
第三,C是比較接近機(jī)器語言。
Third, C is reasonably close to the machine. When you're working with pointers, bytes, and individual bits, things like
optimization techniques start to make a lot more sense. There's also utility in knowing exactly how something works underneath the hood -- this helps a great deal when something you're trying to do in a higher level language seems way slower than expected, or just doesn't work at all. You also tend to get a better picture of advanced topics like exactly how
networking works. A higher level language will make it a little bit simpler, but it'll be harder to understand what's going on, and when things stop working, it's much better to know
exactly what's going on so you can fix it. Additionally, if you like computer science as a discipline, or just like knowing
how things work learning the details of the system is great fun.
實(shí)際上,很多有趣的編程都可以用C來做--比如,系統(tǒng)軟件和數(shù)據(jù)管理系統(tǒng)(Berkeley DB)。如果你想寫一個(gè)比較復(fù)雜的web程序,C也是一個(gè)很不錯(cuò)的選擇。如果你想寫一個(gè)非常好的,快的,C也是很好的選擇。你可以用C來寫整個(gè)操作系統(tǒng),想用Java來做這個(gè)事情是非常難的,對(duì)于腳本語言來說是幾乎不可能的。而且C是一門非常簡潔精煉的語言,它使得非常有趣的編程看起來更優(yōu)雅,你的編程之旅將會(huì)有一個(gè)很好的開始。
In fact, a lot of fun programming is done in C -- for instance, system software and data managers such as
Berkeley DB. If you want to be able to do more than write a simple web app, C is a great language. If you want to write a great, fast game, C is again a great choice. You can write an entire OS in C. It'll be much harder to do so in Java, and nearly impossible in a scripting language. And the language, being succinct as C is, will probably make your fun program more elegant looking to boot.
我對(duì)于這篇文章所談的話題,想補(bǔ)充幾點(diǎn)。
1、學(xué)好C,可以幫助理解其他語言中的一些概念。
比如Java中的引用的概念,如果理解了C語言中的指針的概念,就能很好的理解“引用”這個(gè)概念了,而不理解指針的概念想把引用的概念理解的很透徹,是比較難的。
2、學(xué)會(huì)了C語言,再學(xué)習(xí)其他語言會(huì)感覺到更輕松。
Object-C,Java,C++等等很多高級(jí)語言的語法都與C是相似的。學(xué)會(huì)了C后,基本上只要花上一周的時(shí)間了解一下其他語言的特性,就基本上可以看懂其他語言的源代碼了。
3、從現(xiàn)實(shí)角度來考慮,學(xué)好C,找到一份好工作的可能性也是大大增強(qiáng),特別是對(duì)于剛畢業(yè)的大學(xué)生,或工作經(jīng)驗(yàn)比較少的程序員。現(xiàn)在需要有C語言基礎(chǔ),擅長于C語言的,工作崗位也是比較多。比如拿現(xiàn)在非常流行的iPhone,iPad等設(shè)備的應(yīng)用程序,開發(fā)語言就是Objective-C語言。Objective-C是蘋果Mac OS X、iOS平臺(tái)的開發(fā)語言,Objective-C是基于C語言的,增加面向?qū)ο蟮南嚓P(guān)特性。你可以認(rèn)為Objective-C就是另一個(gè)版本的C++,也就是采用了與C++不同的語法,但也實(shí)現(xiàn)了面向?qū)ο蟆D阌辛薈語言的基礎(chǔ),再學(xué)Objective,難度就不大了。
你可以到那些招聘網(wǎng)站去看看,查查iPhone相關(guān)的開發(fā)工程師的要求,是不是很多都要求有C/C++的基礎(chǔ)和經(jīng)驗(yàn)。
還有一些系統(tǒng)開發(fā)和底層比較相關(guān)的,很多都是需要用C語言開發(fā)的。拿信息安全行業(yè)來講,很多安全產(chǎn)品都是用C語言來開發(fā)的。還有游戲行業(yè)很多都是用C或C++。
還有一點(diǎn),很多初學(xué)者認(rèn)為學(xué)習(xí)C很難。其實(shí)我想說的是難并不是計(jì)算機(jī)語言的問題,難的是因?yàn)槟阌糜?jì)算機(jī)解問題的思維還沒建立起來。因?yàn)槟氵M(jìn)入的是一個(gè)新的領(lǐng)域,以前沒有接觸過計(jì)算機(jī)編程,對(duì)于怎么用計(jì)算機(jī)來解決現(xiàn)實(shí)中的問題的這種思維你還沒有建立起來,畢竟用計(jì)算機(jī)解題的思維,和用數(shù)學(xué)解題的思維還是有些不一樣的,所以你會(huì)覺得學(xué)習(xí)C語言很難。
如果你在學(xué)習(xí)C語言的同時(shí),再進(jìn)行一些程序員的思維訓(xùn)練,我覺得情況就會(huì)大有改善。