Roger Sen

Roger Sen

exploring area

18 May 2023

Keep your code simple, Wirth style

On keeping your code simple (because you know you only write it once, but you maintain it for the rest of your life), there’s a funny story in The School of Niklaus Wirth: The Art of Simplicity By László Böszörményi

I still vividly remember the day that Wirth decided to replace the elegant data structure used in the compiler’s symbol table handler by a mundane linear list. In the original compiler, the objects in the symbol table had been sorted in a tree data structure (in identifier lexical order) for fast access, with a separate linear list representing their declaration order. One day Wirth decided that there really weren’t enough objects in a typical scope to make the sorted tree cost-effective. All of us Ph.D. students were horrified: it had taken time to implement the sorted tree, the solution was elegant, and it worked well – so why would one want to throw it away and replace it by something simpler, and even worse, something as prosaic as a linear list? But of course, Wirth was right, and the simplified compiler was both smaller and faster than its predecessor.

This is what it really means to be an engineer: test a hypotesis, discover is not cost effective and without ego, remove it to have something simpler.