As someone who learned to code recently (last 3 years), this advice is good but dangerous in the long-term.
I started by typing out other people's code from various books or tutorials, but found that it produced a feeling of "success" that made me lazy in taking the step to producing my own code from scratch. I had that feeling of progress, without actually making real progress.
In my experience the best way to learn to code is to pick a small-ish project that you personally want to use and just get started. You'll screw up a bunch of times, but it's the only true way to learn coding.
Neither way is "the best way to learn code"; both are good ways, and they each guard against the other's harmful influence. Do both: when you want to copy code, retype it thoughtfully; also start a small project to do for yourself and jump in.
I disagree. I have always thought that one of the keys to being a good programmer is reading a lot of other peoples' code, and it's a process that doesn't stop just because you're more experienced. I've been programming for maybe 15 years now, and one of the ways I learn how for example a new algorithm works is still to type in an example and run it.
Integrating the manual activity of typing with the mental activity of thinking about what you're typing in and the visual activity of reading someone else's code just stimulates a lot of different neurons and helps you learn.
If I may add to this, I found it really helpful to comment out every line as I went. Even today, when I want to learn new languages or frameworks I pick a repo on github and copy the whole thing line for line, commenting as I go. I found that this helps a lot.
I work this way too, and for the last several years I have been looking for software that would let me mark up some code without actually changing the underlying source files (keeping the annotations on the side). Putting your own comments in screws up diffs and all sorts of things like that.
you could try stripping comments before diff'ing. If you have single line comments you can use diff -I otherwise try this: http://freecode.com/projects/stripcmt
People have been telling me this when I express an interest in the interwebs, but as someone who only has a loose understanding of what a small project is, how can I pick such a thing?
I started by typing out other people's code from various books or tutorials, but found that it produced a feeling of "success" that made me lazy in taking the step to producing my own code from scratch. I had that feeling of progress, without actually making real progress.
In my experience the best way to learn to code is to pick a small-ish project that you personally want to use and just get started. You'll screw up a bunch of times, but it's the only true way to learn coding.