Python Debugging; Embarrassment, Contracts and Nothing is private

by jesse in , , ,


Random links

(photo courtesy of Sean MacEntee via flickr)

Some interesting bits and pieces (leftovers) from the weekend - I have a tendency to queue up a pile of "read later" stuff or emailing myself a pile of things to talk about/link to/etc. Sometimes, I actually get to go through it all. Today - I get to share it to!

First up - Michael Foord (fuzzyman) did two excellent posts - the first is on privacy in Python - not big-P privacy, but rather the programming/object privacy. It's a good read because it reenforces the point that even if you think you're being clever and hiding something in a closure to make it private, you can still get access to it. Remember too - dunders (__foo) are just name-mangling. In Python, nothing is private (insert bad tasting joke about Python being facebook here).

Michael's second post is on the NamedTuple kerfluffle that was stirred up Kristjan Valur's post on the use of exec() and namedtuple (short version: namedtuple creates a string defining the class and then calls exec to create the object. I think Michael is spot on - I think exec() gets a bad rap frankly, sure - it's something of a hand-grenade, if you use it wrong, you're going to get hurt, but in this case I have to agree with Raymond in his comment on bug 3974 - the current implementation is clear and maintainable. I don't like the sternness of the reply - but he is right. Kristjan's use-case is an interesting one, but I don't think it's one that warrants the removal of the existing implementation. I'm wondering if a "fallback if exec doesn't exist" is worth inclusion.

Then again, I've spoken to people who refuse to use namedtuples because they now know how the sausage is made. I still think the sausage is delicious.

Next is a pretty interesting discussion on a presentation that came out of Pixar on getting over embarrassment in order to get things done - I don't have much to add above the comments on hacker news, except to say I think the same mental blocks they talk about for animators apply to programmers, writers, etc. We hide from code reviews, we hide our writing until we think it's "Pitch Perfect" - when in reality, we shouldn't. We should be sharing, discussing and collaborating earlier, more frequently and more often.

Share and Ship early and often - see also "Don't Go Dark".

Finally, I was happy to see the "Quick and Easy Debugging in Python" post from Jeet Sukumaran - it's always nice to evolve past sprinkling print fairy dust all over your code for debugging - even if we all still do it despite knowing or using PDB. Just to add to his post, if you want to increase your PDB-Fu, I recommend this "Debugging in Python" post by Steve Ferg, and the official documentation for PDB. We should really add a HOWTO for this.

p.s. For additional good-reading, check out "Priorities Don't Exist in a Vacuum" and "First Care"- while not germane to what's I've already written about, they're a good essays on priorities. Thanks to the latest "Back to Work" podcast.