Learn how to apply, not how to copy/paste 0
When I’m learning something new, usually I just start out by reading about it. Many times I will go look at the code that someone else has written, generally with open source projects, and attempt to follow it. What I’m looking for is an understanding of how the concepts work, not just identifying them so that I can reproduce. This may lengthen my initial time investment somewhat, but it pays off in the end.
Code samples are just that: samples. They are usually not representative of real world applications, and in many situations they are not intended to be in the first place. Likewise, code snippets of different strategies or techniques in particular areas of the application are often not pulled out of a real world application either. The point I’m trying to make here is, before you copy and paste code into a real application, make sure you understand what’s going on with that code. If something were to go wrong or not work the way you intended, you need to know how to fix it.
I saw this a lot when I was in school. There were people in the Computer Science courses who could not see the programming language as just a tool used to write software. To them, it seemed to carry some sort of mysticism, the likes of which was not to be disturbed. So what did they do? Copy code out of the book, and hope to tweak it until they got it working.
Most of my understanding of software and programming languages comes from taking a concept that I’ve read about and writing my own scenario with it. When doing so, I am given the opportunity to explore the code, see what each piece does, and modify the behavior in ways to get different results. I experiment. When I experiment, I feel a greater sense of accomplishment than had I just read a book or blog post about a subject. In fact, reading normally gives me the itch to write code these days.
During my reading, I often come across comments on blogs or messages in a mailing list of people asking the authors directly for code that addresses particular situations. I never respond to these people, because it’s never my place; they’re not asking me directly. I always think though that these developers who need code samples for every particular situation must not be learning how to apply what they are reading. After all, the example that the author showed explains how to approach it, why not just take the example and learn from it?
Does learning to apply have any other benefits? Well, I, for one, like to do most of my development without having to Google every time I see something unexpected. If I can’t figure it out based on what I already know, or if the code just smells bad, then I will ultimately resort to this, as there is obviously something I do not know and need to learn. Learning is an endless cycle, and I would not have it any other way.
