2026-09-04
My first blog post was about revisiting the code of Reasoning Realm, after an 8 year hiatus. That was just 1 small change, though, and over the last few weeks I've been revisiting it properly. It's now polished enough for me to declare V1.0.0 done.
There were a lot of problems with the code. One that stands out to me is the way the selection tool worked; it had plenty of bugs, and its state was represented with 2 booleans (effectively 3 since the active tool was also checked). I tried to fix the mess by adding another boolean before realising this'd make more sense as an enum, representing the current state of the selection. JavaScript doesn't have enums so I just used a string (selState in the V1.0.0 source), which was close enough.
Replacing the booleans with an "enum" suddenly made everything far easier to handle, and less buggy. There's probably some deep, insightful message here about experience giving you knowledge of different approaches and the intuition to know which one to use.
Anyway, I remember working on Reasoning Realm back in 2016-2018, and encountering one particular bug, which seemed almost intractable to me, until, after a great amount of investigation and confusion, I figured out it was because a function had a for loop with a variable called "i", and within that loop it called another function that also had a variable with the same name, and they collided. Instead of realising that I should've used the "var" keyword to make them local, I blamed JS, thinking it poorly designed, and just gave the variables different names. Pretty much every variable in the entire codebase was global, even when they definitely shouldn't've been.
In retrospect, was JS in the wrong here? Maybe; Lua doesn't have this particular problem, although even in Lua, non-iterator variables are global by default, like JS. I still think I should've been more careful about criticising JS for things I didn't understand.
I also remember being confused by the fact that assigning one array to another didn't copy it, which of course does not confuse me anymore. I "solved" that "problem" by using .slice() for 1D arrays, sometimes pointlessly, and for 2D arrays:
clipboard = JSON.parse(JSON.stringify(rectCellList));
I don't use that anymore.
It feels nice to now be able to say I've been working on a project for 10 years. It makes me feel like a real hacker.