The point is that the act of typing it does help understand the code.
I don't know if there's any psychological basis for this, or if anyone else does this, but personally I jot down loads of notes when learning things and playing with ideas. However, I rarely read back over them. Instead, just the act of writing them down is sufficient to stick them in my brain.
I guess the same applies to learning with code samples.
The point is that the act of typing it does help understand the code.
I guess it works for some people, but not me. And I've copied a lot of code. I'm from the generation of kids that would copy hundreds of lines of code from Compute! magazine. I rarely understood the code as I was typing it. Only after when I could look at it holistically and tweak it, could I understand it.
The primary purpose of typing in modern code is just to make you slow down and really, really read it.
Unfortunately, looking back with hindsight, Compute! et al were not good places to learn about code because the programs in the back were optimized so heavily that there was hardly anything to get a grasp on. Especially the programs that were just a long, long series of DATA statements and a small stub to load them somewhere, then jump to them. Tweaking them afterwards was your only hope.
But wouldn't just really-really reading it do the same thing more efficiently.
I've learned tons from using Firebug. In part because I could start with prewritten code and tweak, and read, and tweak, and read. If I had to enter all the code manually into Firebug (no copy and paste), I think I'd have better muscle memory for typing some of the stuff, but I don't think I'd be a better developer for it (not that I'm a web dev, but just sayin).
Most people's brains aren't trained for reading things properly unless it's with the intent of immediately applying what they read. They can try really hard to read carefully, but their brains are simply not in the right mode to absorb the material the same way they would if it were being put to use. It's hard to even become consciously aware of how poorly you're learning, because it feels like you're really concentrating.
I've finally gotten to the point where I can tell when my brain isn't learning like it should, but I still can't just will that mental state away.
"But wouldn't just really-really reading it do the same thing more efficiently."
If it works for you, go nuts. It's a surprisingly rare skill, but I think it exists. Every once in a while I can reach that level (mostly in code reviews; for some reason that makes it easier).
I do this, too, even sometimes writing out code in a notebook. For example, I gained a clearer understanding of recursive algorithms after I "expanded" a few examples by hand.
You type the code in so that you get practice at typing the code in since in order to write code you have to type code in...a lot of it. If you don't then you're only learning 1/2 of writing code.
Another reason is because anyone who's good at coding learned it this way. Anyone who's bad at coding tends to just copy paste. Usually, you should copy what people who are good at something do.
I don't know if there's any psychological basis for this, or if anyone else does this, but personally I jot down loads of notes when learning things and playing with ideas. However, I rarely read back over them. Instead, just the act of writing them down is sufficient to stick them in my brain.
I guess the same applies to learning with code samples.