Implicit Things

As a learning exercise, I converted a piece of Javascript code i’d written into CoffeeScript.

So what’s wrong with this?

Oh that’s right, initialize doesn’t get called.

It must be “initialize()” when you want to call a function w/no params. But when you do have params, you can leave the parens off. What inconsistent bullshit is this? I guess it’s nice that “initialize” by itself is a statement w/o a side effect. But then when you run it through the compiler (when the hanging return isn’t there), it spits out “return initialize;”, which isn’t what I meant at all and could be a side effect for anyone trying to maintain this down the road. Better to make it explicit that this thing won’t return anything a caller can (ab)use, until and unless I choose to make that the case.

So I’ve been adding hanging returns so the compiled code returns nothing as often as it should.

Sigh, I don’t know that I dig the whole implicit “return whatever was on the last line” thing that so many of these terse scripting languages have. And it strikes me as a weird idea to try and save on parens.

So the CoffeeScript adventure begins, but I’ll be damned if I’m not already building the defensive programming idioms in.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.