Archive for the ‘A Coder’s Guide to Life’ Category

The JavaScript Fallacy

April 26th, 2011

As someone with a rampant interest in UI engineering, I work a lot with JavaScript. I’d venture to say that it’s one of my favorite languages, mainly because it’s quick and flexible, but relatively clean…like a cat. Also like a cat, it can be a fickle, fickle beast. Here’s something I ran into yesterday:

// true stuff
0 == false;
1 == true;  

// also true
"0" == false; 
"1" == true;

// to be expected
0 ? true : false == false;

// WTF?
"0" ? true : false == true;

// or in another light
if ("0") { alert("I will show up"); }
if ("0" == true) { alert("I will not"); }

Clearly we have some temperamental1 loose typing. Stupid cats2.

1 This is, not at all, how I thought this word was spelled. From now on, I’m saying temp-er-a-mental.
2 Note, I actually like cats… Even if they are whorish.

A Coder's Guide to Life, Fleeting Sanity

Getting Pulled Over

September 9th, 2010

You’re just cruisin along, thinking of your latest killer app idea, when lights start flashing behind you. After the initial burst of adrenaline pierces you to the core and shortens your breath, you briefly stop to consider the technology of the trailing officer’s light bar (rotating beacons or LEDs). But then you manage to pull yourself out of your internal dialog, which was going over LEDs superiority as a light-bar technology, given its better visibility, no moving parts, and more efficient energy usage. What do you do next?

The first part is relatively straightforward:

catch(RetardException e)
    Officer.Arrest(You);  /// Do not pass go, do not collect $200

The next part gets a little more complex:

float getTicket()
    float fine = officer.GetFine(you.Speed - context.SpeedLimit);

    while (officer.IsTalking)
        try {
            if (you.Gender == "Male")
            else if (You.Gender == "Female")
                /// ?

            if (officer.LetOffWithWarning(you))
                fine = 0;
        catch (UncooperativeException e)
            if (e.MyTaxesPayYourSalary == true)
                fine *= 2;
                fine *= 1.2;
    return fine;

The elusive black box that is the officer’s LetOffWithWarning() function (highlighted above) is probably of particular interest. It’s probably a combination of factors involving the mind set of the officer as well as your behavior and is probably worth much deeper research. The dramatic sobbing attempts (which, as seen above, only work if you’re a woman) are an attempt to incite a true return value for LetOffWithWarning. Everything else is pretty much targeted at keeping you out of jail.

A Coder's Guide to Life

Out of the bag

May 17th, 2010

How to program your way out of a paper bag:

function exitPaperBag()
    yourself.location = "outside the paper bag";

Obviously this is not the only way to do this–every language has it’s own paradigms to contend with.

A Coder's Guide to Life