Archive

Archive for the ‘python’ Category

One Honking Great Idea

June 8th, 2010

I really enjoyed From Python Import Podcast’s two-parter on the Zen of Python, but I’ve been thinking that they may have missed something really interesting in the last item in the Zen:

Namespaces are one honking great idea — let’s do more of those!

For a long time, I had largely overlooked this one myself, because on its face it seems frivolous and perhaps too specific. Up to that point, the Zen is all broad strokes and elegant generalizations, and suddenly BAM! here comes this thing about namespaces that’s full of colloquialisms and exclamation points, and it feels very tacked on and strange and arbitrary, like a sort of gangly teenager trying to fit into a more mature crowd.

Naturally, the conversation in the podcast went straight down the nerd rabbit hole to talk about the meaning of namespaces, and completely neglected the real meat here, which is a pity because this might actually be one of the most important aspects of the Zen.

This is an expression of the enthusiasm and joy that pervade the Python community.

This is Python’s “Get Excited and Make Things.” This is a formal declaration that it’s all right to get excited about stuff that we make. This is a mission statement to go forth and create new delights, so that those who encounter them may be similarly inspired. That above all, this stuff should be fun.

Think about that the next time you’re crafting some Python code and see if it doesn’t change how you approach things.

python, thoughts , ,

Freeform Night at Clepy and the Ghost of Gary Bernhardt

April 13th, 2010

April’s Clepy meeting saw a much smaller than usual crowd, and a much more casual program–everyone who’d been lined up to give talks had had to bail at the last minute. So instead of covering anything formally, we spent a relaxing two hours enjoying beer, pizza, and various freeform, impromptu lightning talks. You couldn’t even really call them lightning talks since we had no time limit, just an unspoken gentlemen’s agreement to yield the projector cable when the time was appropriate.

Steve Dee showed off his CWRU senior project, jsPrettify, a bit of Javascript tomfoolery to automatically turn ASCII sequences into appropriate (and arguably prettier) Unicode equivalents. We also had a nice chat about the Closure Javascript tools that Steve had been introduced to while interning at Google. (Some aspects, like the provide/require system, remind me a lot of Dojo, and while it seems intriguing, reading some other opinions has me back in the skeptical category.)

Mike Crute showed us his not-yet-ready-to-release tool for automating provisioning and deployment of VPS nodes and the apps they serve, which seems like a really slick way to react to traffic needs (consolidate apps onto fewer boxes during low traffic periods, rearrange on the fly if someone’s site is spiking). He also showed off something else that I mostly missed, so the Python code we glimpsed (featuring a lone “Oh, my…” comment to apologize for the 100-line method that was about to commence) didn’t really mean a lot to me.

We had a brief glimpse of Mike’s desktop wallpaper (a demotivational poster featuring a stern-looking John McCarthy) which inspired me to create this little gem (sorry in advance, Gary!):

gary-bernhardt-as-john-mccarthy-programming-completely-wrong.jpg

Nick Barendt gave a quick introduction to Buildbot while I VPNed into work to prep my own demo of Das Blinkenlights, my little AIR app for monitoring the current build status of our various build slaves at work. The Python code to emit the JSON feed that Das Blinkenlights consumes hasn’t yet been released to the public, but I have permission from the Powers That Be to do so, so I should get around to it before too long. (Beware my extremely unfinished and gross Javascript code in Blinkenlights–it’s still in very rough shape at this point).

We had a new member tonight who was interested in applying Python for developing web apps, so we may try to pull together a “web framework shootout” for next month, which I envision as four or five different presenters simultaneously live coding the same basic web app (probably a wiki, blog, or to-do list) using different toolkits. We’ll need to see about some cabling and KVMs, I think, so that we can rapidly switch back and forth between presenters. More details to follow, I’m sure…

If you’re in Northeast Ohio and want to hang out with smart, friendly people who like Python, come on down! Meetings are held on the second Monday of the month aboard LeanDog’s awesome boat, and we have an official pizza and beer fund going to supply us with tasty treats. It’s a good time that I highly recommend.

clepy, humor, photoshop, python , , , , , , , , , , ,

Exceptions, Error Recovery, and Man Purses

March 31st, 2010

My friend and coworker Aaron Oliver has had a lightbulb moment about exceptions, error recovery, and man purses that Python folks might be interested in reading.

python

Ten Years

March 9th, 2010

Today (technically yesterday at this point, I suppose) was my ten year anniversary at AG Interactive.

I’m frankly astounded that it’s been so long, so soon.

Once upon a time, there was a 23-year-old version of me, leaving behind the miseries of being an IBM road warrior to sling code for an internet startup with its sights set on an IPO, where lunches were free and the foosball was fast and furious. I was psyched to be able to see both my fianceé and the inside of my apartment on a daily basis. I was a Perl zealot, but willing and curious to learn Python (in spite of my perception that it Just Wasn’t That Great).

Since then I’ve fallen out of love with Perl (she was nuts, man!) and found that Python might in fact be my soul mate of programming languages. We didn’t IPO, the free lunches have long since passed, and I don’t play nearly as much foosball as I used to, but the culture’s still a lot of fun. (At the very least, daily finger missile battles keep us on our toes!) The apartment has been upgraded to a house, the fianceé to wife (that’s another ten year anniversary coming up soon!), and we’ve added cats and a kid to the domestic mix.

All in all, it’s been a decent ten years. I just can’t believe they happened so fast!

python, work

“Teach Me Dependency Injection” at Clepy

March 8th, 2010

The stars finally aligned in a configuration that allowed me to return to Clepy, our local Python group. It was really nice to see some folks that I hadn’t in forever, including some long-lost ex-AGI people that I hadn’t caught up with in what seemed like forever.

We did tonight’s meeting in the “Teach Me X” format made popular by Steve Holden’s “Teach Me Twisted” open space at Pycon 2009. One of our newer compatriots, Chris Miller, had been hearing a lot of buzz about dependency injection and wanted a deeper exposure to it, so he played the questioner while David Stanek played ringleader to the group discussion. The format was a lot of fun, and a good way to engage the group without having a more straightforward and less-interactive “eyes-forward” Powerpoint extravaganza of death, though the conversation did seem to be dominated by a few voices that had had the most experience with DI in their professional lives. But overall it was good, and I think that at least a few people had lightbulb moments, and I suspect that even us seasoned DI nerds achieved some insights into the subject as well.

I’m eager to try out the “Teach Me…” format at work, where I’ve got some peer education to-dos that I’ve been struggling to figure out how to structure without causing roomfuls of eyes to glaze over.

In other news, Cleveland Give Camp is coming up in July, and they’re eager for all types of participation–so whether you want to help organize the event or want to participate (they’re particularly seeking code-slingers and graphic designers), this looks like a great opportunity to Do Some Good.

Clepy are a nice bunch of smart folks; meetings are held on the second Monday of the month aboard LeanDog’s awesome boat. And now we have an official pizza and beer fund, so we can enjoy a bit of a treat whilst geeking about. If you’re in Cleveland and are interested in Python, it’s definitely worth joining in. I certainly hope to make it a regular part of my extracurricular life again.

clepy, python

Atomisator Configuration for Unified Python Planet

May 9th, 2009

Robert Kern asked me to share my Atomisator configuration for the Unified Python Planet. So, here it is:

[atomisator]
 
# sources
sources = 
    rss http://www.planetpython.org/rss20.xml 
    rss http://planet.python.org/rss10.xml
 
# filters
# "doublons" is French for "duplicates" --  this is what de-dups the feed
filters =
	doublons
 
# enhancers
# I'm not using any, just leave this blank (default)
enhancers =
 
# outputs
outputs =
    rss /home2/mpirnat/webapps/pirnatwp/static/unified_python_planet.xml "http://feeds2.feedburner.com/UnifiedPythonPlanet" "Unified Python Planet" "A uniqued union of the Official and Unofficial Python planet feeds.  Generated by Atomisator FTW!" 
 
# database
database = sqlite:///atomisator/unified_python_planet.db

The example configuration files that come with Atomisator are really good at illustrating how you would use them; I’ve omitted the explanatory comments from my example, but they’re in the examples and will point you in the right direction. Thanks again to Tarek for this very handy tool!

geekery, python , , , , ,

The Diaper Pattern Stinks

May 9th, 2009

I mentioned the “Diaper Pattern” in a recent post and got some comments asking what the term meant. I had hoped to just link to an explanation, thinking it was a well-known antipattern, but several minutes of frustrated Googling have left me convinced that there’s actually a tiny knowledge gap to be filled here.

“Diaper Pattern” is a term that I picked up from working with Matt Wilson and David Stanek. It’s an anti-pattern about naively over-broad exception catching. A very basic example in Python might be:

try:
    do_something_that_might_throw_various_exceptions()
except Exception:
    pass

If anything at all goes wrong in do_something, the except will catch and silence it–but we know that errors should never pass silently (unless explicitly silenced). It’s called a Diaper because it catches all the shit.

In practice, unless you have a good reason to catch everything, it’s a lot better to only catch the specific exceptions that need special handling, so that you’ll know right away about any runtime surprises and where they came from:

try:
    do_something_that_might_throw_various_exceptions()
except IOError, e:
    # handle just IOErrors; let everything else make noise

Maybe it’s just a coincidence, but I’ve heard the term used more by developers who have young children than by those without kids.

geekery, naughty-words, python , , , ,

The Zen of Doing It Wrong

May 6th, 2009

A coworker unearthed this little treasure today… I think it’s a vestigial structure to assist Diaper (anti)Pattern treatment during testing or debugging, but it’s still gross to see it in real, live production code. (Oddly enough, I couldn’t find a good “Diaper Pattern” link whilst Googling about–surely I’m not the only one who uses this term?) Anyway, without further ado:

        try:
            os.remove(filename)
        except:
            raise
            pass
        try:
            os.remove(os.path.join(TMP,'out-%s' % base_filename))
        except:
            raise
            pass
        try:
            os.remove(os.path.join(TMP,'properties_%s.lock' % brandid_human))
        except:
            raise
            pass

If an exception is raised, raise an exception… It has a certain zenlike beauty to its awfulness. The use of the Diaper Pattern is bad enough, but this guarantees blowouts!

geekery, python, wtf , , , ,

Return to Clepy; Possible End of the Universe

April 13th, 2009

Forget the LHC–a far surer sign that the end times are nigh is that I’ve finally been able to attend Clepy for the first time in about 15 months. (In case I do actually cause the implosion of the universe, let me take this opportunity to apologize in advance. Sorry about that; my bad!)

We had an extra-long social period at the start of this month’s meeting (while there were some misadventures with pizza delivery), but the bonus casual time was great for meeting new people and getting caught up with people I hadn’t seen in a long time.

The main focus of the meeting tonight was a live demo of Gary Bernhardt’s TDD tools, Dingus and Mote. I’d seen a little bit of Dingus from following Gary on Twitter, but had not ever seen it in action, and Mote was brand new to me. Dingus is a mocking library that attempts to aggressively and magically isolate the code under test from everything external to it. Mote is a lightweight spec-runner (not “test-runner!”) that wants to remove as much verbosity as possible. Thanks to some nifty decorator-fu that makes it super-easy to rig up automatic Dingus isolation in your Mote specs, the two combine to form some kind of TDD Voltron. Mote’s a little rough around the edges, but it’s brand new and under heavy development, and shows a ton of potential. If you’re interested in testing or TDD, check out these tools!

The unsung star of tonight’s presentation was Gary’s .vimrc, which contains powerful magics for quickly running tests from within vim and displaying their success or failure as a green or red line at the bottom of the buffer. There’s plenty more fascinating arcana in there, so it’s nice to know that his dot files are on bitbucket too. I’ll eventually peruse and dissect them.

This was Clepy’s first meeting at LeanDog’s floating headquarters; I was really pleased with it as a venue. It’s centrally located, easy to get to and from, is highly geek-friendly, and is quite novel as a meeting space. (It’s on a boat! Next to a submarine! How great is that?!) I hope we can continue to meet here as it really seems like a positive change. It was also great to see new faces and meet new people tonight; it seems like the group has really started to thrive independently of AGI.

Above all, I really hope to be able to start attending regularly again, even if it does trigger the apocalypse.

clepy, python, testing , , , , , ,

A More Excellent Unified Python Planet

March 28th, 2009

Good news, everyone!

After a couple days of playing Twitter tag with Tarek Ziade, we finally met up for lunch at PyCon, where, in addition to having a lovely conversation, he was kind enough to give me a personal tour of his Atomisator framework for data aggregation.

Atomisator is much savvier than Yahoo Pipes at things like removing duplicates and not mangling content, so I’ve kicked Pipes to the curb and hooked up the Unified Python Planet feed to my Atomisator output.

What this means for you, lucky reader, is that everyone who subscribes to the Unified Python Planet should not only stop getting duplicates, but, more importantly, have legible code samples directly in the feed. (It’s okay if you need to take a moment to process this joyous news. It makes me pretty damn happy.)

Please let me know if you experience any flakiness with the new, improved feed.

I want to give major, major thanks to Tarek! Atomisator is really well suited to this purpose, as well as some other stuff I’m now curious to tinker with.

geekery, pycon, python , , ,