Thursday, April 27, 2006

Other side of the Coin

There is always a counter example. Having just saying that dynamically typed languages are better then statically typed ones, I find my own counter example in the kind of bug that static typing would have caught easily and simply.

Recently I have been looking at two things, Databases (and especially SQLObject) and cross platform GUI libraries. I seem to have settled on wxPython for this. wxPython comes with a great Python shell called PyCrust, this once was it's own project but the maintainer agreed to fold into the main wxPython distribution.

PyCrust has a namespace browser (which I thought was quite a nifty idea) except every time I tried to brows SQLObject it would hang. And the problem was name collision. The Namespace inspector in PyCrust checks for objects that expose a method called _getMethodNames, which will assist it in displaying the correct attributes. It just so happens that SQLObject has a class which will happily return a callable object for almost any attribute you ask it for. PyCrust is expecting a list of strings and gets an instance of a class it knows nothing about, to make things worse this class overloads the + operator for its own purpus (it is used
to dynamically construct SQL queries from python expressions).

An error is only generated 20 lines of code later when PyCrust attempts to iterate over what a local variable which should contain a list (but dosn't). Has this changed my mind about dynamic typing... Well No. In the end every language feature has benefits and drawbacks. Dynamic typing opens the door for bugs of this type which can be quite hard to locate. It also gives flexibility, a lot of flexibility, this can make the programming effort a lot easier, as it promotes decoupled code.
In python it is relatively easy to create an objects which are interface compatible with other objects without having a dependency on them.

No comments: