Togetherness AKA: simple testing can prevent most critical failures

One of the things I love about my profession is that it inspires empathy for people that I have never met, never spoken to or even exchanged emails with.
How? Through code comments (that’s how).

Code comments are generally short and acerbic.
On occasion they are philosophical.
And in the best cases they reveal a profound sense of confusion and utter desperation.

Here are some gems from Ding Yuan’s talk on testing in large scale distributed systems.

catch (NoTransitionException e){
// why can this happen? Ask God not me.

This one’s from an optimist.

/* if this happens, hell will unleash on Earth. */

It almost certainly isn’t.

/* TODO: are we sure this is OK? */

This one’s from a realist.

/* TODO: this whole thing is extremely brittle */

There are a few more of these, and a great deal of fascinating insight into the benefits of static review in Ding Yuan’s complete talk.

Prepare for glory, 2015.

Close your eyes.
Make a wish.

Here are some (perverse, and in some cases: sadistic) things that I hope that no one will say this year. Or any other year. Ever again.

“We just want a few simple pages with a few links, there’s no need for things like testing.”

“We don’t want to get into a situation where we have to spend lots of time writing things down, because we haven’t got time.”

“This is going to be a quick and straightforward thing, there’s no┬áneed for documentation.”

“Can we just get something up and running quickly and then do all of this other stuff (read: testing) a bit later on?”

“Can we not just keep track of things via email?”

“Sorry but we can’t say ‘no’ to him/her.”

Posting now, but I’m sure I’ll think of more later on today …

‘continue’ versus ‘else if’

When looping over an array and taking different actions based on the the contents of each array entry the traditional approach is to use an ‘if’ with an ‘else if’. I think that, in these circumstances, code becomes more readable if we use an ‘if’ with a ‘continue’.

Let’s take a list of things (we’ll do this in javascript)

var fooBar = ["foo","bar"];

and loop over it using ‘continue’

for (var x=0; x<=fooBar.length;x++){
    if (fooBar[x] === "foo"){
        console.log("we have foo");
if (fooBar[x] === "bar"){
    console.log("we have bar");

and then lets loop over it again, this time using ‘else if’

for (var x=0; x<=fooBar.length;x++){
    if (fooBar[x] === "foo"){
        console.log("we have foo");
    else if (fooBar[x] === "bar"){
        console.log("we have bar");

I like the ‘continue’ snippet. It’s just that little bit easier for me to read. That little bit more explicit. The paths through the code are clearer to the naked eye.

js.perf suggests that using “continue” instead of “else if” within a “for” loop introduces a minimal, barely noticeable performance dip:

I’m a ‘continue’ man from now on.