2013年/04月/15日
程序员都是自学
When I was a teenager I played high caliber baseball. I’m competitive to a fault and when I decide I want to be good at something, results usually follow. Now I’m a third year undergrad studying computer science. There’s something critically different between programming and sports though: A pitching coach teaches you how to pitch, but a CS professor doesn’t teach you how to code.
I was surprised that neither my TAs nor professors critiqued my code during my first year, but grew concerned after my second year. The assignments were larger and the problems tougher, but even after submitting some 2,000 lines of code in my data structures class, I never once had a comment on my code — if my program compiled and my unit tests demonstrated correctness, that was enough. It wasn’t until a small group project that I realized how ugly some code could really be, and I started asking questions about what good code really was.
But what is good code? I take a lot of time to make my code readable and self-documenting. I try to follow the UNIX philosophy on simplicity, that I should make my program work above all and only optimize if there’s a need. I keep in mind asymptotic complexity. I avoid threads unless I really need them. But I honestly don’t know if that’s good code or not (honestly, I think I’m a bad programmer).
I’m lucky enough to have worked with some students I think are great programmers, people who have interned at Microsoft, Google, Amazon and the like. Their opinion is generally the same, that most of what they learn is from self-reflection or picking up on other programmer’s habits. Even the ever-practical engineers share my sentiments. So here’s my claim:
All programmers are self-taught.
My education is giving me awesome tools: data structures, algorithms, database design, concurrent programming, network programming, agile development and different programming paradigms. But these are all tools, and even though they translate to much more efficient and smarter programming, you can still use them wrong — I’ve seen horrible code come from students who do exceptionally well in these classes.
I don’t think it matters if you study computer science, software engineering or get a college diploma, if you’re going to write code for a living, you’d better be ready to teach yourself.
在我十几岁的时候就开始玩甲级棒球。我水平很差,但当我决定要做好什么事时,最终总能如我愿。现在我是计算机专业 3 年级的学生。在编程上,有些事情和体育是截然不同的:棒球教练可以教会你如何打棒球,但一个计算机教授却不能教你如何编程。
我很吃惊,在整个大一期间,我的老师或教授从来不点评我的代码,大二时更是如此。我们的作业很多,题目很难,但在完成了数据结构课上的 2000 行的代码后,我从来没有收到过老师的任何一条评论——只要程序能编译通过,单元测试显示没有错误,这就行了。直到遇到了一个小组开发的项目,我才认识到我的代码写的多烂,我才开始询问:好的程序应该如何写。
但是,什么样的代码才是好的代码?我花了大量的时间来提高代码的可读性,添加注释。我努力模仿 UNIX 的哲学观,力求简约,首先让程序能跑起来,在此基础之上,在需要的情况在进行优化。复杂的东西要逐步增加。除非必要,我不使用线程。但是,说实话,我不知道这是不是好的代码(说实话,我觉得自己水平很差)。
我很幸运,能和一群优秀同学一起工作,他们都是出色的程序员,他们在微软、谷歌、亚马逊等公司实习。他们的观点都很一致,认为自己的知识都是自己总结或从其他程序员那里学到的。即使是非常资深的软件工程师也有这样的看法。所以,我的结论是:
所有程序员都是自学成才的。
我受的教育给了我很好的基础:数据结构,算法,数据库设计,并行计算,网络编程,敏捷开发以及各种编程模式。但所有的这些,即使是它们使得编程更高效和更精巧,你仍然可能用错它们——我曾经看过一些学生在这些课程上学习成绩非常好,但写的代码却让人想哭。
我并不认为学过计算机科学、软件工程或得到一个大学文凭会有多大的用处,如果你想靠写代码为生,自学是你不可缺少的途径。