Tooling blame game

For those using a RSS reader, subscribe here: rss.xml

Yesterday, while programming the solutions to Day 4 of Advent of Code 2021, I stumbled into a mistake that was way too fun to not share.

The painful experience

So imagine the following scenario: you have just written a source file with 100 lines of code, tested individual components, and are now running it for the first time as a whole. You are doing REPL-driven development, and are now running the main function inside the REPL. You are waiting, and waiting, and there is just no output. You begin to question why, so you jump back to the source file and reload that into the REPL. But it does not load it, it keeps getting stuck on “Loading file X into REPL”. And before you know it, your entire editor stutters, CPU and RAM usage explodes, and your system almost becomes un-usable. “A restart will fix it right?”

As you restart the development environment, the same thing happens again. You intensely stare at the code you have just written. Five minutes ago it still had value, but now seems to only be some random text on your screen. Not admitting your defeat just yet, by fleeing to a programming language with tooling you know, you give up for the coming 1.5 hours.

Getting back on track

So after this break, you see that all tooling reading your code breaks. The breakthrough is when you realize an empty REPL still works. And that one can read in other source files just fine. So there is something wrong with the code you have written, it bricks everything apparently. So after a binary search through your written code, (with a possible entire system freeze at each step) you find this snippet:

63: (defn bingo? [card]
64:   (or (bingo-horizontal? card)
65:       (bingo-vertical? card)))
67: (-main) ;; And it is this expression that ruins it all
68: (defn score-of-card [card]
69:   (if (bingo? card)
70:     (reduce + (map score-of-row card))
71:     0))

It got lingered around while debugging. Probably a wrong copy-paste. But that main was not correct yet. The main happens to loop forever. And thus, while reading this file in, it was getting stuck on evaluating it.