09 2 / 2011
Subclasses & the Source Code
Last week I hit a bug I knew I could fix - but I couldn’t. After a day of banging my head against the wall, I came to one conclusion. I needed to reread ‘Learning Python’ to get a better handle on the language.
One of my talents I just recognized is the ability to find patterns. I can see the repetition in Django docs for views or forms, and basically riff off that to hack something together. Its the same with guitar. I can’t write or read music, but I can pick up songs and play those over and over again. The problem is that I didn’t really understand the what & why with Python & Django. I knew what to do, but I didn’t know why or what was going on. I had to face reality and go back to the basics. I was lacking key pieces of information that weren’t allowing me to solve the problem. Turning back to ‘Learning Python,’ connected many of the dots with OOP- subclasses & overloading methods to be specific. Understanding these pieces led me to understand Django on a whole new level.
A few of you have told me, “Read the Django code” when I send a question your way. For a n00b, this is a daunting proposition. The thought process to a beginner is, “I barely understand my code. What can I possibly get from reading the source code?” To the n00bs out there, the critical piece of information you need to understand is a subclass. Recognizing the methods and attributes of the superclass are what you can access through a subclass is a key connection I hadn’t completely made.
When someone tells you to “Read the code,” it means look to see what are the methods and attributes you inherit from the superclass. I think making this simple connection has allowed me to turn the page with my coding. Instead of just copying patterns, I am comprehending what is actually going on, and what makes Django such a powerful framework. To the n00bs out there, “Understand subclasses, then read the source code.”
Permalink 3 notes