To bracket or not to bracket, making sense of single line conditionals

Thursday, March 19th, 2009

It’s taking me about 3 months to finally come up with a strong opinion about single line conditionals, but I now have a firm position:

“In the long run, it’s a bad idea to drop the brackets and put a conditional or iterator on a single line.”

Essentially sort of thing:

public function testResults(score:Number):void
{
    if(score < MIN_PASS) sendNotification(YOU_FAIL)
    else sendNotification(YOU_PASS)
}

Should always be this:

public function testResults(score:Number):void
{
    if(value < MIN_PASS)
    {
        sendNotification(YOU_FAIL)
    }
    else
    {
        sendNotification(YOU_PASS)
    }
}

Even when writing in a language that doesn’t use brackets, i.e. so called pure block languages like Python and Visual Basic, proper formatting should be used rather than single lines. If a language does use brackets, there is no excuse not to use them.

My argument follows this logic:

“Since debugging code is 20 times harder than writing it, by that definition you won’t be smart enough to find errors in clever code.”

(more…)

Technophile Chatter

Wednesday, March 18th, 2009

Here’s an online conversation with a good friend of mine on IM!

oculart:      hows it going with you these days
ghostmonk:  good man
ghostmonk: busy
oculart:     that’s the word on the streets isn’t it
ghostmonk: Myron and I are making this crazy ass site
oculart:     sweet, for who
ghostmonk: same one we’ve been working on for the last 8 months
ghostmonk: for this at risk women’s group in Winnipeg
ghostmonk: funded by ***
oculart:      ah cool, is an interactive story?
ghostmonk: no
ghostmonk: it’s a content site
ghostmonk: interactive story would be awesome
ghostmonk: nice idea
ghostmonk: I can show you
ghostmonk: beta.**********.com
ghostmonk: runs completely off a cms
ghostmonk: that’s why there is dummy content in there right now
ghostmonk: there is still a ton of work left to do
oculart:     alright let me check it out
oculart:      i like the resizing browser animation snap thing
ghostmonk: There’s more there than meets the eye
ghostmonk: the content is completely managed
ghostmonk: there is a back end
oculart:     do they have a lot of content they are going to be adding
ghostmonk: I guess so
oculart:     i don’t really believe in having cms for a lot of sites
oculart:     seems like a waste of programming time unless content is updated hourly
oculart:      I think it’s foolish when more resources are used on building a back end application when its just as easy to republish updated content unless it needs to be dynamic content (more…)