Dec 15 2007

Tailor, Mercurial, Leopard

I was getting this error when trying to use Tailor with Mercurial on Leopard:

Common base for tailor exceptions: 'hg' is not a known VCS kind: No module named mercurial

Mercurial was installed, so the error mystified me. Turns out to be a problem
with python versions in use. Leopard’s python is version 2.5.1, but mercurial
from MacPorts depends on python 2.4, and so MacPorts installs python24. So when
running tailor with python 2.5 and trying to load the mercurial module which is
installed for 2.4, not 2.5, it naturally fails. The workaround is to run tailor
with python 2.4 instead, which works fine.

#! /bin/sh
# Save as ~/bin/tailor and chmod +x
tailor=$HOME/src/tailor/tailor
exec python2.4 $tailor

Jul 8 2006

Duck Typing Defended

Ever since I discovered ruby I’ve loved dynamic typing. I never paid much heed
to people who got their knickers in a knot over how dynamic typing is “unsafe”.

While working on Ardour this
summer
, I’ve literally been wrestling with C++,
all because it is statically typed. The code I’ve been writing over the past
month could have been done in one week with half my brain tied behind my back
(which is the usual situation, by the way), if only C++ were dynamically typed.

In other ways static typing hasn’t exactly got in my way, it just causes me to
jump through hoops that seem silly, unnecessary, and inelegant. A simple
concrete example will help. I’m doing undo serialization, and of course Ardour
already serializes other things in order to save sessions. In C++ this means
lots and lots of otherwise unrelated things all inherit from a common
serializable base class. This is why multiple inheritance is necessary in C++.
In Java you can use interfaces, which is better than multiple inheritance but
not by much. In dynamic languages, you don’t even have to give it a second
thought. You just make sure everything that needs to be serialized responds to
a serialize method, et voilá!

So as I’ve been wrestling I’ve had this nagging feeling that it’s *me* that’s
broken, not C++. Have I become so spoiled by dynamic languages that I can’t
program efficiently in a static language anymore? Are the static people right
and one day my whole world will come crashing in and all my ducks will keel
over? Feelings of self doubt are part of being human, and these were some of
mine this summer. Then I read a blog post by Bruce Eckel on Strong Typing vs.
Strong Testing
and my mind was put at
ease. The thrust is, dynamic typing is good, and testing is necessary. I think
this quote about Robert Martin (a C++ guru) sums things up nicely:

Robert came to more or less the same conclusion I have, but he did so by
becoming “test infected” first, then realizing that the compiler was just one
(incomplete) form of testing, then understanding that a weakly-typed language
could be much more productive but create programs that are just as robust as
those written in strongly-typed languages, by providing adequate testing.

I have a thought along these lines. Let’s say you’ve got duck typing in full
swing as in his examples. Now in the real world it sometimes happens that you
choose a common ambiguous word for the duck method, like “run” perhaps, but
more often than not you have methods that are named fairly specifically, like
“speak” or “jump”. The static argument is that you might accidentally call the
method on something that won’t do what you anticipate because it’s not of the
right type. But really now, how many of your objects that implement “jump” are
going to be the wrong kind of objects in your application? Often the answer is
none. So you jump through hoops for no reason.

Do read the article, it’s fun and well-written. Even if you come out still
clinging to your beliefs that static typing is Good and Wholesome, at least
you’ll see that us dynamic people aren’t necessarily lazy, stupid heathens.