Static typing isn’t so bad
So I’ve spent the past week or so putting together a simple Rails application. For the most part I’m impressed, but it’s clear it only 0.10 for a reason. I developed the app using PostgreSQL, which has a native boolean type (non standard of course), which ActiveRecord translates nicely. My web host does not have PostgreSQL installed, but the more popular MySQL.
So I installed MySQL locally and ported things over. It’s things like setting up users and permissions that bugged me the most because Google couldn’t turn up anything useful. The actual port was trivial, things like changing serial to MySQL’s auto increment thing. That is until I found MySQL doesn’t have a native boolean type, it’s just an alias for TINYINT(1). And no matter what this ticket says, they aren’t recognized properly as booleans by ActiveRecord and are treated like ints. So where before the framework did things like translating a checkbox’s default value of ‘on’ to true, I now had a bunch of silent failures.
This is where static typing is nice. It would tell me that ‘on’ is a string and not the boolean value TRUE. Things like ‘if @user.enabled then’ would fail because enabled is an int not a bool. But instead it just runs with incorrect behaviour. Thankfully there weren’t that many things I had to track down.
So this round goes to static typing. Eventually I’ll start seeing an upside to dynamic typing, but at the moment the years of Java programming still make me want to declare every little thing.
