If you want to learn from a piece of code, you should type it out, instead of just reading it. The value of typing code:
Typing code may be like riding a bicycle. I’m surprised how much more detail I see the first time I ride my bicycle over a road I’ve driven on, mostly because I’m moving slower but also because there’s an additional muscular dimension to the experience.
I love this bicycle metaphor. The slowness of biking engages my brain in an entirely different way than running or driving. Even the mechanical sounds are more pleasant; the consistent whirr of the chain is so much more calming than the revving up and down of a gasoline engine.
The value of typing code holds very true for me; I usually get very little by simply reading code in books and articles. But when I take the time to type it in and actually try to run it, I struggle with it more (not all code examples are perfect) and get more out of it. You should give it a try.
Even better, I think, is to type it out with changes. Test your ability to mess with it, and to anticipate the result.
I do that probably half the time. Half of that time, I end up botching something trivial, which distracts me from learning from the actual example. My rule of thumb lately is, simple examples are fine for customizing on-the-fly; more involved examples are typed in verbatim.