Ghosts in the machine
”One of the biggest differences between hobbyists and professional programmers is the difference that grows out of moving from superstition to understanding.”
-Stephen McConnell
In my early days of programming I often fell into the trap of refreshing a broken application multiple times to make sure it was “really broken”. In hindsight this seems silly. A computer does not behave randomly, however, deterministic behavior can lead to some interesting quirks.
function getGreeting() {
const hour = new Date().getHours();
const greetings = [
[22, 'Working late?'],
[18, 'Good evening'],
[12, 'Good afternoon'],
[6, 'Good morning'],
[4, 'Whoa, early bird!']
];
return greetings.find((greeting) => { hour >= greeting[0] })[1];
}
Do you see the problem? (Hint: This will work flawlessly during office hours but result in a late night support call) Along the same lines...