A journalist I follow on Twitter recently asked me the best way to start to learn how to program. It’s a question I get asked a lot and, although it has been said before, here’s my advice for learning how to program:
The most important thing, by far, is to find a project you are dedicated to completing. Pick something that will disappoint you or your employer if you don't finish it. There are two reasons for this. First, you'll learn best if you attach new knowledge to old. Seeing code though the lens of a problem you know how to solve is an invaluable way to understand it and remember it. Second, it will give you the momentum to scale the steeper parts of the learning curve. You need to be more afraid of missing your deadline than you are of programming!
Next, pick a language. Go to a bookstore and flip through the first chapter of both a Python book and a Ruby book or browse the web for introductions to the languages. There are other languages but these two are excellent. Pick whichever language delights you more. They're quite different. Python I find more to the liking of perfectionists while Ruby is attractive to left-brained folks. Of course there are plenty of artists who use Python and neat-freaks who use Ruby. Don't anguish over the decision! If you can't decide, simply flip a coin. You really can't go wrong with either. And they're like Romance languages: If you're good at one you'll be able to learn the other pretty quickly.
Having picked a language, you should learn however is best for you. If you like videos, pay for good video/screencast training. If you learn best with books, buy a book. If you like being in a class, do that. My colleague Lena Groeger wrote an excellent guide to the resources on the web for code learners. Bookmark it.
And then: Do your project and don't stop until you're done. And then do another. Just write a lot of code. It’s worthwhile to keep going, even when projects don't push you to learn parts of the language you don't already know. Repetition will help you retain knowledge and you’ll do everything a little better each time. Even very accomplished developers do this. Programming knowledge is perishable and won't stick unless you keep using it.
Get a Github account and learn how to use git (start with Al Shaw’s guide) so you can rewind to earlier versions of your code when you go down blind alleys. Try to read lots of other people's code if you can't figure out how to do something, or just to see other approaches to the same problems.
You'll learn best when you break things and have to fix them. Python and Ruby both give great error messages. Google them and you'll see how somebody else fixed the same bug. Don't just copy and paste the solution, but try to understand what was broken and how the fix works. If you Google your error and nobody else seems have gotten it, you’ve probably made a basic error like a misspelling or a missing comma.
Soon you'll find yourself knowing intuitively what different errors mean how to fix them. When you go to add a feature to your software and realize you know exactly how to do it, you’ve become a coder.