写给新手程序员的一封信
写给新手程序员的一封信
首先,欢迎来到程序员的世界。在这个世界上,不是有很多人想创造软件并解决问题。你是一名hacker,属于那些愿意做一些有挑战性的事情的人。
“当你不创造东西时,你只会根据自己的感觉而不是能力去看待问题。” – WhyTheLuckyStiff
对于下面的文字你不必完全接受,所有这些来自一个其貌不扬的程序员。我喜欢把事情做到最好,而不是对原来的东西修修补补。
仅仅是因为爱好开始做一些创新,这是一个很好的开始!如果你说“我要先学习一下再开始做”那么你永远不会真正开始。每个人都需要从某个地方开始,所以现在打开你的编辑器开始写代码吧。
下面是一些很重要的建议,虽然有人并不认同,但我保证你看完我的分析以后会站在我这一边。一开始,先不要管算法和数据结构。大多数简单的程序不需要用到算法和数据结构,所以当你真正需要时再去学习。编程一段时间以后,你就会知道在哪些地方用到他们。这时知道算法的名字并了解它们的功能,然后找一些相关的论文去理解算法并动手编程实践。如果没有现成的函数库(其他程序员提供的可重用代码),你用自己喜欢的编程语言来实现它。
0. 选择一门好的编程语言,一门你自认为可以用它快速地做出一些有用东西的语言。
不要选择C语言作为你第一门编程语言。也许选择C语言会给你一种过时的满足感。虽然它比早期的汇编语言提供了更好语法描述,但是今天C(或者C++)不是能够快速编写软件的语言。毫不偏袒的说,我建议你学习一种动态语言。选择一种你觉得语法(文档)让你使用起来更舒服的编程。为此,你可能需要花费一些时间来在几种不同的语言之间进行比较。这么做目的不是为了让你感觉更好或者让编程更容易。更快地完成自己的作品并且能够看到成果,才是激励你编程的源动力。不要选择一门需要某种重量级的IDE(IDE是一种能够帮助你编写并运行代码的工具)才能轻松编程的语言。你所需要的仅仅是一个文本编辑器。(注:原文并没有标号,是我们加上的,请大家别忘记了哦,我们是从零开始数数的。:) )
1. 选择一个好的编辑器。
编辑器对程序员而言,就是像是弓对弓箭手一样重要。这里有一些推荐的编辑器:
· SublimeText 2 – 如果你刚开始编程,推荐使用SublimeText 2
· Emacs – 学习曲线陡峭,快捷键复杂。如果你想定制自己的使用习惯,需要学习Emacs Lisp.
· Vim – 不仅操作简洁而且它默认包含在linux的发行版中,所以深受大家欢迎。我开始使用了2年Emacs。由于Emacs的快捷键操作过于复杂,我的双手开始经常疼痛,这迫使我转向了Vim阵营。了解Vim的快捷键是非常有必要的。当你在远程的服务器上编辑代码时,你唯一不需要安装的编辑器就是Vim。
注意!Emacs和Vim可能已经成为成为古董了。但是,它们都具备一些现代编辑器多不具备的功能。
2. 选择一个你可以从中学到东西的操作系统
Windows不会教会你任何东西。使用Windows你唯一学会的就是打开一个exe(可执行)文件来安装软件和使用它。可能刚开始的时候你会觉得很酷,但是长远来看,如果你立志成为一个web开发人员,可能还是要具备基本的linux知识,尤其是当你要发布程序的时候。Linux也允许你根据自己的要求来定制程序。Macs也很酷,但是我认为你现在经济上还负担不起。
3. 不要通过复制粘贴来做备份
一个新手程序员通常会把文件复制粘贴到一个临时目录下面来进行备份。这也许也是他们唯一知道的方法。不要那么做!你需要使用版本控制软件。我强烈推荐使用Git,它是个目前很流行的版本控制工具,而且使用起来非常简单。对一个Git新手,有一个良好的社区和很多参考资源来学习。(除了Git之外,还有mercurial, darcs, fossil等等。但是我还是建议从Git开始,我有很多的理由来支持Git,这里就不多费口舌了。)
4. 知道去哪里寻求帮助
参加一个和你相关的(你使用编程工具相关的)程序员社区。比如StackOverflow就是程序员的Facebook。那里没有消息状态和回复,取而代之的是问题和答案。除此之外还要学会使用IRC。IRC是一种老式的聊天室,现在还在被大多数开发人员用来分享技术信息和帮助解决问题。
5. 培养你的礼仪
知道什么时候问问题。你遇到的大多数问题都是别人碰到过并且在Internet上能够找到解答的。在IRC或者任何论坛里发问之前,先搜索一下google(或者blekko)来看看是不是有现成的答案。在IRC上问问题需要有耐心。永远记住,人们只是处于好心来免费帮助你。有时你发问以后需要几个小时才能有回复。所以,耐心等待。除此之外,记得问问题的时候要礼貌。世界很小,你怎么对待别人,别人就会怎么对待你。
6. 结交朋友,技术书籍只能教你解决常见的问题(他们说:书是死的)
当你在捣鼓一些程序或者从程序的作者那里学习,你能学到一些书本上没有的东西。当你散步的时候,请和遇到的朋友打招呼。你肯定不是唯一的程序员。和其他的程序员一起交朋友一起工作。你会注意到,当一群技术爱好者在一起的时候,不论话题是从什么地方开始,最后总是以技术话题收尾。这是必然的现象。所以你可以尽情参与。在你的黄金年龄努力编程,我能告诉你的是,我在开始6年前寻找朋友并开始讨论编程,从那时起才学到那些书本和文章不会我的东西。所以我总是说,我的编程经验有6年,因为只有那个时候开始,我才开始与人交流并开始感觉真正地开始学习编程。
7. 参加开源项目
为开源项目编写代码能带来回报。这不仅仅是帮助别人,你留下的代码会被其他人使用或(可能)改进。当别人给你的代码添加功能或者提出修改意见时,也是在提高你的编程水平。开源软件项目不一定要是一个大工程,编写一个下载youtube视频的小程序也是很有用的。更重要的是,你会惊奇地发现你编写的代码会成为与他人有效沟通的桥梁。
最后,若干年之后如果本文的内容曾经对你有一点点的帮助,作为回报请写一封类似的信给希望开始编程并不知如何入手的朋友,有可能的话请纠正本文中过时的内容。
智者说过,掌握某个东西需要10年或10000个小时,也就是汉语中的“十年磨一剑”,所以不用着急。
英文原文:An open letter to those who want to start programming
An open letter to those who want to start programming
First off, welcome to the fraternity. There aren’t too many people who want to create stuff and solve problems. You are a hacker. You are one of those who wants to do something interesting.
“When you don’t create things, you become defined by your tastes rather than ability."
– WhyTheLuckyStiff
Take the words below with a pinch of salt. All these come from me – a bag-and-tag programmer. I love to get things working, rather than sit at something and over-optimize it.
Start creating something just for fun. That’s a great start! There’s no way you will start if you say you “need to learn before doing”. Everybody’s got to start somewhere. Fire up your editor and start writing code.
Here’s something important which people might call bad advice, but I’m sure you’ll stand by me when I’m finished saying why. Initially, screw the algorithms and data structures. They do not have generic use-cases in most simple applications. You can learn them later when you need them. Over a period of time, you’ll know what to apply in situations. Knowing their names and what they do would suffice to be able to pick some paper, dust it and implement it. And that is… if no library (other programmers' re-usable code) is available, to do it in the programming language of your choice.
Choose a good language. One that you think you can produce something useful in short time.
So let C not be your first language. That might give you the satisfaction of doing things the really old-n-geeky way. C was the solution to the problem Assembly Language was. It offers better syntactic sugar than it’s prominent predecessor – Assemble Language. But today, C (or C++) is not a language that you can produce something very quickly. I would suggest that you use a dynamic language – I won’t sideline any options. Choose a language whose syntax (and documentation) you think you might be comfortable with. For this, you might want to spend some time trying out different languages for a few hours. The purpose of choosing such a language is not to make you feel better and that programming is easy. Completing stuff faster and being able to see the output keeps you motivated. Don’t choose a language that requires a special heavy-weight IDE (tool that helps you write code and run it) to program better in the language. All you should need is a text editor.
Choose a good editor.
An editor is to a programmer, like how a bow is to an archer. Here are some editors to get started with…
· SublimeText 2 – recommended if you are just starting.
· Emacs – huge learning curve. Complex key shortcuts. And to be able to customize it, you’ll need to learn Emacs Lisp.
· Vim – used by many for it’s simplicity and the fact that it comes with linux distros by default. I used Emacs for 2yrs and then switched to Vim to run away from emacs’s complex key strokes and when my little finger on both hands started hurting. Knowing vim keystrokes is a must. When you work remotely and try to type out code on some server from your computer, you’ll know that the only editor available from the command line without any installs, is Vim.
Watchout! Emacs and Vim might be really old. But they both have some features which even most modern editors don’t have.
Use an operating system that’ll teach you something.
Windows won’t teach you anything. The only thing you learn using Windows is to click the .exe file to install the software and use it. It may seem cool in the beginning, but in the long run when you have to deploy applications, especially if you are aspiring to be a web developer, you’ll need atleast basic knowledge of linux. Linux also allows you to customize stuff the way you need them to be. Macs are cool too, but I assume that you cannot afford one of those now.
Don’t copy-paste files to backup stuff.
It’s usual among amateur programmers to copy-paste files to some temporary directory in order to backup them. That’s the only way they seem to know. Stop that! Use a version control software. I strongly suggest Git, since it’s popular and easy to use. It has nice community and resources to support new-comers. (Apart from Git, There’s mercurial, darcs, fossil, etc. But just start with Git. I’m not going to bother you with the reasons for suggesting Git).
Know where to get help.
Join a community that you can relate to (with the tools you use). StackOverflow is Facebook for programmers. There are no status messages and comments. Instead there are questions and answers. Also learn to use the IRC. It’s an old form of chatrooms and is now being used by mostly developers to share information and helping each other.
Develop your netiquette.
Know when to ask questions. Most problems you face might have been stumbled upon by others who might have already posted on the internet for answers. Before asking on IRC or any forums, google first (or should I say blekko first) to see if there’s already a solution to your problem. IRC needs patience. Remember people are helping you for free out of goodwill. Sometimes it might take hours, for someone in the chatroom to respond to you. So wait until they do. Besides, be polite. It's a small world. Karma, good or bad, comes back.
Meet people, because books only teach you routine stuff (oh and the "book" is dead they say).
There are some street smarts that you’ll learn when you tinker with stuff or learn from those who do it. Roam, meet people and say hello. You are not the only programmer in your place. Make friends and do stuff with them. If you've noticed, when a couple geeks get together, whatever the starting point of the conversation be, it always ends up getting technical. It's bound to happen. Enjoy it. Programming for a good number of years, I can tell you that I learnt nothing more than what the books and articles said, until I starting meeting people and getting technical with them 6yrs back. So I always say that I’ve been programming for 6yrs, because that’s when I started meeting people and feel I really started to learn.
Write opensource code.
Writing opensource code is giving back. It’s much more than charity. You are leaving code that others can use and improve on (maybe) for years to come. It also helps you refine your skills when someone else adds to your code or suggests changes. Code that you opensource doesn't have to be big. It can even be a useful little program that downloads youtube videos. Moreover, you’ll be surprised, that your code will often help you start and have interesting conversations with people.
Lastly, when years pass, return this favour, by writing a similar letter to someone else who asks you for such help. And possibily correct me.