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!


Now read this

Yosemite: Snake Dike

Snake Dike route (red section was roped, blue was unroped) We woke up just after 3am. Trying to stay quiet, we put on our packs and made our way out of the sleepy campground. After a mile on flat ground we started the 2000 foot ascent to... Continue →