Thursday, March 8, 2012

Assumption is the mother of all f***-ups (Robert's Rule #12)

[Tweeted 2011-05-11]

How many times have you made an assumption? If you're like me, you make them every day. Of course we're familiar with the problems that can be caused when we assume something about another person, and when we assume something about a person based on their race, nationality, religion, sexual orientation, physical ability, gender, et cetera we're guilty of a bias that in many cases would be illegal in the workplace.

We're all used to the warnings, sensitivity training, and reminders from the 'human resources' department regarding making assumptions about people, but what about making assumptions about things? This is also quite dangerous, especially when we make assumptions about software.

As an example, let's look at how an HTMLElement object is created. It's simple code, really...so we assume that something like...
var obj = document.createElement("script");

...will give you an object with the same interfaces as...
var obj = document.getElementsByTagName("script").item(0);

That's the assumption at least, and it's supported in the documentation. In reality, it works that way for every browser that doesn't use a special HTMLElement constructor (cough Internet Explorer cough).

What happens when you assume that some software behaves like other software or follows the same (published) standards? You write code that doesn't work correctly when you make that assumption, that's what happens.

If you're lucky, you find the problem before any real damage is done; if not, hopefully you discover it quickly and are able to minimize the damage. Not finding these little hidden 'implementation differences'  has damaged the reputation of a few otherwise good developers, so take care to remember that assumption is the mother of all f***-ups (Robert's Rule #12).

No comments:

Post a Comment