Don't Go In The Basement

What if there was a serial killer putting the "execute" in "executing your code"? Recently, I was working on some tests within the codebase in company. I can't share the exact code, but I can paraphrase:

$ cat foo.js

var foo = 'bar',
baz = {
},
monkey = {
pirate: {
ninja: 'zombie'
}
};

if (baz.pirate.ninja !== monkey.pirate.ninja) {
console.log('This test is failing');
}

What was the result of running that?

$ node foo.js


node.js:116
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'ninja' of undefined
at Object. (/net/homestar/home/jmullan/imvu/platform/foo.js:10:15)
at Module._compile (module.js:373:26)
at Object..js (module.js:379:10)
at Module.load (module.js:305:31)
at Function._load (module.js:271:10)
at Array. (module.js:392:10)
at EventEmitter._tickCallback (node.js:108:26)

If only there was a way to spot that bloody hand print on the door to the cellar.

$ cat foo.js

var foo = 'bar',
baz = {
},
monkey = {
pirate: {
ninja: 'zombie'
}
};

if (baz.pirate) {
if (baz.pirate.ninja !== monkey.pirate.ninja) {
console.log('This test is failing because the ninjas are not the same.');
}
} else {
console.log('This test is failing because baz has no pirate.');
}

I know this is basic, but people still go to the basement and get eaten by cannibals in movies. Please take the time to imagine that the people who will be next working on your code are nightmare hell beasts who want an excuse to consume the souls of your children.

0 Responses to Don't Go In The Basement

  1. There are currently no comments.

Leave a Reply

About You