Monday, July 09, 2007

Optional typing: best of both worlds?

There continues to be an ongoing debate over which is better, static typing or dynamic typing.  I argue there are advantages to both, but if I have to choose, I favor dynamic. 

I'll make no bones about it, I'm one of those that loves Python, personal productivity topping my list of reasons.  Python is an excellent language for many/most uses, but I run into places where pure dynamic typing is counter productive.  I say keep the dynamic typing, but give me the ability to optionally specify a variable's type. 

Optional typing has several advantages.  First, it helps make code self documenting, especially with arguments and return values.  Second, type declarations can result in cleaner code than assert statements.  And finally, the interpreter can provide performance advantages when the variables' types have been declared and checked.

Optional typing would be the best of both worlds.

Labels: ,