Python Debugging; Embarrassment, Contracts and Nothing is private

May 31st, 2011 § 1 comment

Random links

(photo cour­tesy of Sean MacEn­tee via flickr)

Some inter­est­ing bits and pieces (left­overs) from the week­end — I have a ten­dency to queue up a pile of “read later” stuff or email­ing myself a pile of things to talk about/link to/etc. Some­times, I actu­ally get to go through it all. Today — I get to share it to!

First up — Michael Foord (fuzzy­man) did two excel­lent posts — the first is on pri­vacy in Python — not big-P pri­vacy, but rather the programming/object pri­vacy. It’s a good read because it reen­forces the point that even if you think you’re being clever and hid­ing some­thing in a clo­sure to make it pri­vate, you can still get access to it. Remem­ber too — dun­ders (__foo) are just name-mangling. In Python, noth­ing is pri­vate (insert bad tast­ing joke about Python being face­book here).

Michael’s sec­ond post is on the Named­Tu­ple ker­fluffle that was stirred up Krist­jan Valur’s post on the use of exec() and named­tu­ple (short ver­sion: named­tu­ple cre­ates a string defin­ing the class and then calls exec to cre­ate the object. I think Michael is spot on — I think exec() gets a bad rap frankly, sure — it’s some­thing of a hand-grenade, if you use it wrong, you’re going to get hurt, but in this case I have to agree with Ray­mond in his com­ment on bug 3974 — the cur­rent imple­men­ta­tion is clear and main­tain­able. I don’t like the stern­ness of the reply — but he is right. Kristjan’s use-case is an inter­est­ing one, but I don’t think it’s one that war­rants the removal of the exist­ing imple­men­ta­tion. I’m won­der­ing if a “fall­back if exec doesn’t exist” is worth inclusion.

Then again, I’ve spo­ken to peo­ple who refuse to use named­tu­ples because they now know how the sausage is made. I still think the sausage is deli­cious.

Next is a pretty inter­est­ing dis­cus­sion on a pre­sen­ta­tion that came out of Pixar on get­ting over embar­rass­ment in order to get things done — I don’t have much to add above the com­ments on hacker news, except to say I think the same men­tal blocks they talk about for ani­ma­tors apply to pro­gram­mers, writ­ers, etc. We hide from code reviews, we hide our writ­ing until we think it’s “Pitch Per­fect” — when in real­ity, we shouldn’t. We should be shar­ing, dis­cussing and col­lab­o­rat­ing ear­lier, more fre­quently 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 Debug­ging in Python” post from Jeet Suku­maran — it’s always nice to evolve past sprin­kling print fairy dust all over your code for debug­ging — even if we all still do it despite know­ing or using PDB. Just to add to his post, if you want to increase your PDB-Fu, I rec­om­mend this “Debug­ging in Python” post by Steve Ferg, and the offi­cial doc­u­men­ta­tion for PDB. We should really add a HOWTO for this.

p.s. For addi­tional good-reading, check out “Pri­or­i­ties Don’t Exist in a Vac­uum” and “First Care”- while not ger­mane to what’s I’ve already writ­ten about, they’re a good essays on pri­or­i­ties. Thanks to the lat­est “Back to Work” pod­cast.

  • http://twitter.com/felipejcruz Felipe Cruz

    It worth men­tion pudb.. it‘s much more friendly from peo­ple that came from IDE debugging

    http://pypi.python.org/pypi/pudb

What's this?

You are currently reading Python Debugging; Embarrassment, Contracts and Nothing is private at jessenoller.com.

meta