Friday, 6 August 2010

Ruby Tuesday

Well, Ruby Friday to be precise.

I've been looking at Ruby and Ruby-on-Rails for some cool web development action and have hit on a number of things that bug me. No doubt I'll find find good reasons for them, but at the moment...

 The one thing that really bugs me right now (quite unreasonably so, as it isn't broken, just an odd design decision) is the handling of constants. You define a constant by the mechanism of starting a variable name with a capital letter, so var_name is not a constant whilst Var_name or VAR_NAME is (I prefer all upper-case to make it absolutely screamingly obvious). This isn't a coding convention that the interpreter pays no heed to, it's an actual language convention, but the really annoying part is that a constant isn't constant.

If in Ruby, you try to assign to an already-defined constant, the interpreter will quite happily let you, but at the same time will warn you that you're doing a bad thing. This half-way house to me makes little sense; either a constant should be constant by language enforcement or completely by convention, especially as it is presumably possible to make optimizations in the interpreter if constants are genuinely constant that isn't the case if they might change.

It is said that Ruby follows the principle of least confusion; in this case, I'm not sure this is the case.

No comments:

Post a Comment