《转》
去年九月我写了一篇挺受欢迎的博文,叫 《想学Rails? 这样开始》。 许多读者看完文章后,当面或用Email向我提了大量问题;也有很多人真正投入到了Rails学习中。我也很自豪地向很多人推荐了这篇文章,因为其中的内 容真的具有可操作性,并且对读者真的有帮助。从那之后到现在,我的编程功力又长进了几个甲子,于是又有了下面这篇文章,记录我对“如何学编程”的再次思 考。
这篇文章是写给那些真心要编程的人看的——那些憋着一股狠劲儿,一定要做出个什么真东西的人;而不是那些“听说编程好玩”的人。在我看来,这些人都不太可能真的整出个像样的东西来。
无论从我个人经验,还是众多访谈的结论来看,只用晚上和周末等业余时间来学习编程是十分糟糕的办法。断断续续的学习方式,你的脑子根本没机会养成编程式的思维方式,你很难把之前学习的内容捡起来。一定要把你的时间尽量多的利用起来。
一种改善的方法是参加“编程训练营”之类的项目;你不但要花整整九周时间,还要花费一笔不小的学费。这些付出可以对你有所约束,督促你学到东西。你必须全情投入,否则钱和时间就打水漂了。
“我用 Codecademy 学会编程了!”
不知道有多少人这么说过了。但是如果持续的观察六到八个星期之后,这些人就都歇菜了。
我告诉你们为什么用Codecademy学习不长久:
在你想做的项目里,先找一个小的来做。我做的第一个项目叫做“今日所学”。软件里只有一个文字输入框,你每次输入一些文字,软件按照时间降序来显示输入内容的列表。仅此而已。
你的第一个项目一定就是一坨屎。但是它是完整的项目,而且是你完成的。这才是最牛逼的地方。
我每天写代码,我都会把当天所学的一两个知识点放进去,这样我下一次编程时就会写的更好。你会不断的从你的代码库里引用老代码,或从网上扒来的代码。一旦你真的懂了这些代码,你就能把它们用起来。
Tommy Nicholas去年12月写的博客里也提到了这个观点。只有你把代码敲出来,你才能真的学到东西,你才能发现你对某些代码还没弄透,也希望你去google一下你的疑问,这样才能学到越来越多的东西。
开始学编程之后,你要为自己找到一两个编程老师带着你学,但别学了一点就在那些不会编程的朋友面前穷显摆。
我一直相信,如果你把想做的事儿说了出去,那事儿就永远只能停留在你嘴上了。所以除非对方是你可以请教的老师,不然就闭上嘴,低下头,老老实实编你的程。
空谈误国啊!
编程就是要重复的犯错误,犯重复的错误,弄清楚错在哪儿,再改正错误。下次再碰到相似问题(你一定会碰到的),你就会想起之前蹂躏你的那些代码和你的对策,吃N堑,长一智。
当然,搞定编程的成就感也会让你爽到内伤。“那东西是我想出来滴!”的快感是我活着的动力!我为之着迷!但获得快感的路也灰常艰辛。不断寻找你的动力,不断前进!
我一朋友的朋友总是没完没了的问我各种磨唧问题。他试图在正式开始前看清所有可能会搞不定的地方。
这是一种最操蛋的学习方式。正确的方法是:选门语言(Ruby 或 Python)、买本刚出版的书、把自己当个白痴、立马开始学!立马开始第一章!有必要就把第一章再看一遍!你根本没法想象有多少知识是你不知道的!不过没关系,你会慢慢都搞明白的。大家都是这么过来的。
祝你好运。
英文原文:Zack Shapiro,编译:@张飞alex
译文链接:http://blog.jobbole.com/37540/
March 31, 2013
Last September, I wrote a post called Want to learn Rails? Start here. which has been pretty successful. I've met and emailed a good amount of people who have follow up questions or are in the middle of learning how to build things with software. I've referred a bunch of people to the post as well. I'm proud that the post is actionable and helpful. Since I wrote that post a while ago and developed my engineering skills much, much further. I wanted to write a follow-up post, some revised thoughts on learning how to code.
This post is intended for working professionals who feels a strong desire to code to build things that they want to see exist in the world. This post is not intended for the person who thinks they should code because they hear so much about it. I mean no offense but I've found those people to be lacking in the short and medium-term fire it takes to learn to actually build software.
1) Nights, weekends are bad
Given my personal experiences and a slew of conversations, I've found that learning how to code only on nights and weekends is a terrible way to go about it. When your brain is not trained to think the way coding forces you to think, it's very easy to lose where you were or not remember a key concept you just picked up. Putting in as much time as possible is your friend.
This point of view is reinforced by programs like Dev Bootcamp which not only require a full nine weeks of your life but also make you pay tuition to attend (which is not a small sum). They make you buy in temporally and financially to ensure your success. You have to throw yourself in or you will fail.
2) Forget Codecademy
“I'm learning how to code! I'm doing Codecademy!”
I don't know how many people tell me this. If I follow up with any of those people six-to-eight weeks later, they've fallen off the boat completely.
Here's why Codecademy doesn't work in the long term:
You're coding in a browser which you literally never do outside of Codecademy. Learning the syntax of JavaScript, Python, or Ruby is good but that's about all you get out of the program, in my opinion. You'll learn these skills elsewhere.
You don't know how to set up a development environment. Any time you have the slightest inkling to build something for yourself leveraging what you've learned in Codecademy, you can't and probably don't know where to start.
You'll need to go through the process of setting up your dev environment which can be incredibly challenging for someone with very little coding experience.
3) Have a real project you want to build
Have something tiny you want to build. One of my first projects was called Today I Learned. It's a text box that you enter stuff into and it shows the date you entered it in descending order. That's all it does.
Your first project is going to be crappy. But it will be done. And it will be done by you. And that's fucking awesome.
4) Everything you build, builds on top of the stuff you've built before
I built Today I Learned and whatever I built next, was better because of one or two concepts I learned while building TIL. You'll constantly be referencing your old code, code other places in the codebase or code from the Internet, once you understand what the pieces mean.
5) Don't copy and paste others' code
Tommy Nicholas wrote a post in December which echoes the same point. You learn things when you write code out. You question what certain pieces mean. Hopefully you Google those questions to learn more and understand more.
6) Stop telling people you're learning to code unless they're technical and you want them to help you
When you're starting out, your goal should be to find a technical mentor or two, not impress your other non-coding friends with the fact that you've taken the first step.
I'm a firm believer that if you talk about what you want to do, you never actually do it. So unless you're talking to someone you hope will be a mentor, close your mouth, put your head down, and keep building.
Loose lips sink ships
7) Coding is failing a ton and understanding why. It's painful and frustrating
The way you learn how to build software is by making the same mistake a few times, learning why that doesn't work, and doing it correctly. The next time you come across a similar problem (and trust me, you will), you'll either remember the way you did it last time or at least the part of the codebase that you struggled in, which you will then reference and remember what you learned from all of that failing.
The rewards for building software are incredible. The feeling of “that came out of my brain” is what I live for. I love it. But the road to get to that point can be tough. Build momentum. Keep going.
8) Stop trying to figure out what you should do and just start.
A friend of a friend kept emailing me with a bunch of questions. He was trying to figure out all of the places he could fail before he even started.
That's the absolute wrong way to go about this. Pick a language, (Ruby or Python) buy a really recent book that assumes you know nothing and just start. Do chapter one. Do it again maybe. The amount that you don't know that you don't know is bigger than you can imagine. Don't worry about that. You'll understand more pieces in time. We all will.
Good luck.
If you have tips for beginners learning how to code, please share them on Hacker News. Your time and effort may really help someone out.