A computer is never wrong. It outputs exactly what you asked for.
Last Sunday happened the presidential French election. Starting at 8 pm, journalists hosted a show revealing the results, and commented along the ballot counting.
Two journalists commented the night, while in the background a chart appeared, with the number of ballots counted for each candidate. This number would grow in real-time with the ballot counting happening in all french cities.
It created lots of heated reaction, especially when they were giving the wrong candidate as winner for almost all of this time.
They claimed to be directly connected to the “Ministère de l’Intérieur”, which is the official source of this data, who is also publishing the results on their website.
The twist is that the data published on the Ministère de l’Intérieur website was right all night long.
After a while, they finally fixed the bug and correct numbers were displayed, creating a huge surprise for a lot of people, seeing the number for their candidate going down (both candidate went down).
France 2 apologized saying that it was a computer error that led them to display wrong numbers “for a short while”. It is a polite way of saying that the program, made by humans, was wrong.
Humans makes mistake. Okay. But there are existing methodologies that helps us prevent them.
Let’s review together how France 2 programmers could have avoided that.
Keep it simple, stupid.
Or, more politely, “Keep it simple, straight”.
This principle is known as KISS.
It consists of not bringing accidental complication to a software by reviewing what you just did. Or in other words, by refactoring.
This way, you make maintenance easy to access, your code easier to understand.
In this context, how would KISS prevent the error ?
Here, the behavior was to display the number of vote for each candidate.
The number of vote for each candidate was already computed by the “Ministère de l’Intérieur”.
Take those numbers, display them.
Instead, they preferred making a whole new calculations based of the number of votes for each candidate for each French city.
And they failed. They introduced a bug counting multiple times the same cities, then displayed numbers way higher than the actual number of votes.
Because they simply didn’t keep it as simple as it should have been.
Even worse, it took them 2 hours and 40 minutes to figure it out and fix it.