Archive for the ‘Writing Code’ Category

Use Your Flickr Account as a Photo CMS

Sunday, May 31st, 2009

It is blindingly easy to use your Flickr account as a Photo Management system for a website.

At it’s very simplest, create a new Flickr account, apply for a API key ( under Explore -> Flickr Services ) and then make an HTTP call to one of the many services available through their API.

If all you want to do is load in your own images, then construct a simple URL using one of the following methods (or one of the hundreds available at Flickr Services): (more…)

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…)