[Tutor] following on

Robert Sjoblom robert.sjoblom at gmail.com
Tue Feb 19 14:01:43 CET 2013

> Could the experts, please, recommend a beginner's book to learn the
> principles of good programming?

I don't know about expert, but I found the Head First Lab's approach
to be really good. The Python book is structured like so:
-Lists introduction
-(PyPi)/creating modules -- this I hope has been changed in future
editions of the book, because PyPi now has a test server for those
learning to use it, instead of people uploading to the official PyPi
server (if you've ever wondered why there are so many modules for
printing lists within lists (nester.py)).
-Error handling
-Saving data
-Work on data
-Web development
-Mobile App development
-Handling input
-Scaling your webapp (which you built in the web development chapter)
-Handling complexity

Each chapter consists of a challenge that you'll work; the work on
data one has a "Coach Kelly" giving you his files on runner times,
wanting it formatted. So first you'll learn to read it in, sanitize it
and everything, and after that you move on to OOP design, where you
create a new class (let's see if I recall it):
class Athlete:
    def __init__(self, name, dob=None, times=[]):
        self.name = name
        self.dob = dob
        self.times = times

    def add_time(self, time):

    def add_times(self, times):

After you've designed the class yourself they go on to mention that
instead of building functionality that already exists --
self.times.extend(times) -- it's probably better to create a class
that inherits from list, like so:
class AthleteList(list):
    def __init__(self, name, dob=None, times=[]):
        self.name = name
        self.dob = dob

In each chapter they go through various approaches on things that crop
up; for error handling it's the add extra logic/ask forgiveness, for
classes it's custom class or inherited class, for saving data it's
custom code vs off the shelf solutions, why you want to create
functions instead of duplicate code and so on. It's well structured,
readable, and have quite enjoyable challenges (compared to the usual
"Hello World" approach that many other books do). So yes, they teach
you Python, but they also teach you the principles of good
programming. I recommend it to anyone who wants to learn Python, but
there are probably better books for *specifically* programming
principles -- this book is more of a bundled deal.

best regards,
Robert S.

More information about the Tutor mailing list