Tightrope walking

Feb 26, 2007 23:24

[Non-coders: it shouldn't matter if you don't know about the specific technical issue that I'm discussing here. Hopefully, I've managed to convey something of what it feels like to code in different languages, which is the important thing.]

I was brought up on static languages. Admittedly, the first programming language I touched was BBC Basic, which had autovivification of variables, but it also had separate namespaces for string and numerical variables. Then I was taught programming properly on Turbo Pascal, which is all about the type system. I learned object-oriented programming on Delphi, which is what Turbo Pascal turned into, and was also heavily typeful (and, incidentally, one of the nicest development environments I've ever had the pleasure to use). When I first encountered dynamically typed languages, in the form of RSI's noxious Interactive Data Language (and later VB), I thought dynamic typing was an accident waiting to happen. Programming without static typing felt like walking a tightrope without a safety net, with the slightest wobble ready to pitch me into the abyss below. Wherever possible, I'd declare variables, turn off everything implicit, and curse if there was no way to do these things.

It wasn't until I started using Perl (and I discover with surprise that I can't remember exactly when that was - presumably around 2000-2002, when I started using Linux regularly) that this began to change. Perl offers no facilities for static typing - it's dynamic all the way. More than that, it's mutably typed - if I ask for "3" + 4, it won't die at compile-time like Haskell, or at run-time like Python, it'll simply convert the "3" to a 3 and return 7. If you ask for an array element that's out-of-bounds, it won't die with an "array subscript out of bounds" error, it'll just lengthen the array so it's big enough and autovivify the extra elements. Yes, this can be slow. But there are plenty of ways of finding out how big an array is, so obviously you did that because you wanted to.

This was presumably painful at first (I can't remember). But after a while, I started to get it. All my old fears were revealed, in the light of day, to be groundless, and even slightly ridiculous - if I wobbled, then the tightrope moved under me, to counterbalance my movement and hold me up. I could walk along the rope as easily as if it were pavement, and on the few occasions where I fell off, it turned out that the bottom of the abyss was actually covered with big trampolines. The sense of liberation was wonderful. Why should I, as a thinking human being, have to worry about the trivial difference between 3, 3.0, "3" and (3), when a machine could do it for me and leave me free to concentrate on the important stuff? I started to code in tune with the language, and as a result my code became simpler, clearer, more robust. I could Say What I Meant, and perl1 was smart enough to Do What I Meant.

Which is why it's so jarring coming back to static typing for Haskell. After grokking dynamic typing, static typing just seems antediluvian. Every time a compilation dies because of a type error (and actually, having to compile code before running it seems pretty antediluvian too), it's like the hip young guy I thought I was talking to has suddently adopted the tone of a boarding school headmaster circa 1950 and caned me for having my shirt untucked and misusing the optative. And if you have no idea what an optative is or in what context you might wish to use one, then you have some idea of my bewilderment at most GHC error messages.

Maybe I'll grow to love static typing again, as I grew to love dynamic typing before it. Maybe (and this is what I'm hoping for), I'll be able to transcend the dichotomy, and come to a deeper understanding in which I realise there is no real opposition. But right now, it's hella frustrating.

1 As any fule kno, Perl is the name of the language, and perl is the name of the interpreter for that language. PERL is something different :-)

computers, programming, type systems, beware the geek, perl, haskell

Previous post Next post
Up