Saturday, April 26, 2008

The Lisp effect

I was writing some Python last night. I couldn't stay on Lisp forever, as much as I'd like to. The code I'm writing has to run on a machine that I don't have control over, so I can't install something like SBCL or even a Scheme implementation. So I'm stuck with the next best thing: Python.

Flowing along test-driven development lines, I was writing some unit tests, and this... "thing" struck me a few times. I was repeating code. Most of it I was able to do away with by abstracting the common bits into helper functions, but there's only so far you can go. I'm still stuck with two unit testing classes that do similar things, but test fundamentally different input classes.

To my dismay, I discovered something.

I disliked writing Python.

Which is weird, because I consider Python a pretty decent language. And there was only one thing from Lisp that I missed: macros. With them, I never would have had to repeat a thing in the first place, and I wouldn't be stuck with two similar unit test classes with nearly the same structure: I'd just write a macro for it.

The sayings were true: Lisp does make programming in any other language unbearable.

Maybe the way to make my units tests more elegant will come to me in a dream or something. Le sigh.

No comments: