Some of the exercises in this set might seem tedious to you, but like eating your veggies, they are sooooo good for you …
This PowerPoint is a review of Zed Shaw’s exercises 20 - 26 in his excellent (HIGHLY recommended) FREE online book Learn Python the Hard Way.
I made this PPT for my journalism students. See their course schedule.
I’ve looked at code, I’ve read explanations, I’ve been doing both on and off for years now, but the usefulness — the purpose — of object-oriented programming techniques just never sank in.
Today is the day when I have, at last, understood. Ah.
I think I had enough programming knowledge (basics, foundation) to cross this gap long before today. It was a matter of application.
What I did not do before now was read, and write out code, and read, and write out code, and repeat, and repeat. It has taken about four days, an hour or two each day. Before, it just seemed like so much extra work, extra planning, extra thinking, that was not necessary for the short programs I have written. And this is still true. It would be perfectly okay for many small programs to be written without objects, without classes. They will run, they will work, they will not have conflicts.
Enter complexity. When a program is complex, when it must be longer than a few dozen lines — and if multiple people will all be writing code for it — then the brilliance of objects makes perfect sense. Because it’s not about making wheels for a car, or Person and Employee, or all those things that are used as examples in explanations of object-oriented programming and how it works. No. It is not about objects. It is about bundling. It is about re-usability. Extending. It is about preventing conflicts that arise when the same word might be used to mean two entirely different things.
Here is what finally made it clear for me:
First, Zed Shaw’s Learn Python the Hard Way, exercises 40 - 43. But not only those. Also what he asks you to do. I take Zed literally. When he tells me to go out on the Web and look stuff up, I do it. I read, I come back, I go out again. I take notes. I run code. I rewrite my notes.
Second, Python for Kids, by Jason R. Briggs, chapters 4 and 8. Chapter 4 is about turtle, a Python module that is often used to introduce children to programming concepts. Chapter 8 is about classes and objects, and partway through the chapter, when it’s talking about two giraffes, I realized the giraffes could be two turtles — which would be objects of the class Pen — and everything fell into place like pieces of a Tetris puzzle when you’re winning.
I had bought Briggs’s book to find out whether anything in it might be useful for teaching college journalism students Python. I had skimmed parts of it before. I ran all the suggested code in the turtle chapter because I had never used the turtle module before. But I had put the book aside a few months ago.
Then I was diligently working through Zed’s exercise 42, and I’m thinking: Classes, Attributes. This is like CSS. This is like jQuery. I see the structure, it’s starting to seem familiar … And then I remembered Briggs’s book. I went back to his chapter 8 and read.
And there it was.
Don’t give up. I think this is the greatest lesson taught by learning to program. We are rewarded again and again for our hard work, sticking to it, trying and failing and trying again. We might become stuck for a time, but we can figure out a way to become unstuck if we only continue trying.
Play, play, play — that’s my advice for how to learn to code.
I’m a big fan of Zed Shaw’s Learn Python the Hard Way, but I think exercises 13–19 are a particularly challenging hurdle to jump if you never studied any kind of programming before.
So here are three supplements to help:
Files to help with
from sys import argv
Files to help with learning functions
Have at it!