pko.ch

Polyglot hacker & Architect

Archive for August, 2008

There’s no silver bullet, but there’s a silver DSCM. And it’s quick.

Saturday, August 23rd, 2008

Pre scriptum: This was dangling in my drafts forever. I just decided to post it as it is.

In this post: Why I use Mercurial (sometimes abbreviated as hg) but not Git, and why I like it.

One day, some moons ago, I watched a presentation with Linus on Git, and how it would forever change our life. He explained why it’s a must-use on a very big distributed team or/and at a personal level. I mostly agreed. I still thought this was just a clever hack to solve merge conflits on svn and keep changes controlled on a mental level. CVS is dead, SVN is not. For most small teams, SVN is just a shortcut for the common workflow one would do with git, except for one little thing: you commit locally, and publish as needed.

Mercurial, or any DSCM, is great for detaching the act of committing work (accepting it as a valid step towards a goal) from the act of publishing work (putting your modifications up for other parties).

I prefer Mercurial over Git for the polish and supporting the anti-”linus is god” movement. I really didn’t like the way I was told he dismissed the idea of using incremental logs. I’m not being an extremist, or i would use Codeville.

Memoization in Python: easier than what it should be

Friday, August 22nd, 2008

I was writing some DB-access-intensive Python application and felt the need to cache function results. After fiddling with some dictionaries, I felt there was some underlying pattern I wasn’t spotting. Then it hit me. I was just memoizing function calls.

So I came up with this decorator.

import functools
import cPickle
def memoize(fctn):
        memory = {}
        @functools.wraps(fctn)
        def memo(*args,**kwargs):
                haxh = cPickle.dumps((args, sorted(kwargs.iteritems())))

                if haxh not in memory:
                        memory[haxh] = fctn(*args,**kwargs)
                
                return memory[haxh]
        if memo.__doc__:
            memo.__doc__ = "\n".join([memo.__doc__,"This function is memoized."])
        return memo

Python is really easy to write.

23 August 2008 – Update: Corrected the bug pointed out by John.
25 August 2008 – Update: Improved as per reddit comments‘s suggestions.

Chand-FAIL-ler

Tuesday, August 12th, 2008

Chandler always looked promising. I was really happy when I heard 1.0 just came out. Because I hadn’t my laptop around, I tried the web version and felt ok with it.

But that was my last step in my trail of Chandler faith. As soon as Chandler Desktop booted up, I was greeted with a soft, warm and fuzzy python exception: “Hey! This function receives one argument, you gave it two!”. Never good.

Tried to report the bug. Need a login for some bugzilla somewhere. Hmm, guess I’ll pass.