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, mount a MacOS directory into a Linux Docker container and run the world’s first case-insensitive Linux distro. Ghosts abound.

One thing I like about computers is that they are fathomable. One can enumerate all the “laws of machine nature” quite succinctly and by doing so remove the need to believe in the supernatural. There are no star charts and psychic hotlines for how your PC will behave this October. One doesn’t need to seek out a prophet in order to explain why your printer works on Sunday, but crashes on Tuesdays. Professional programmers dispense with these reassuring fables and embrace the fact that they are capable of explaining it all themselves.

So why do programmers fall for the double reload trap early in their careers? My guess is that they do not yet know how to find the answers they seek and they’re under time pressure to get things working. It’s faster to throw away existing code and rewrite it than to spend a few days debugging. Ghosts can hide in library code, the operating system, hardware, the interpreter or even the compiler. I find that in the long run, explaining away ghosts is one of the most enjoyable parts of your career so next time your program is behaving mysteriously, let me know!

 
10
Kudos
 
10
Kudos

Now read this

Granite Peak - Southwest Couloir

Granite Peak, highest point in Montana I picked Cassondra up at the Billings airport at 2:30pm. I got a flat tire on the van about an hour before she landed and I didn’t have a spare because I recently ditched it to make room for her... Continue →