Github Repo

Report on last night and some behind the scenes grunt work.

Behind the Scenes
Yesterday, after publishing article 50, I did some behind the scenes work, aimed at resolving a tiny issue, those lateinit variables that I had plugged in so as to give the game’s Imperatives access to the world and room. This was a mistake, and I’m glad that I wasn’t writing it up. My concern was that I had all those nice tests for the Imperative, and those tests didn’t provide a world and room. I felt that fixing them all up with a world and room would be a hassle, so, instead, I created a really interesting structure.

I built an interface for Imperative, with two implementations, SimpleImperative and WorldImperative. With some difficulty, that let me keep my simple tests, yet use the more powerful World version in the game. That was wasteful. There is no other purpose for the Imperative, so creating two of them just to make testing a bit easier was just plain whack. Even worse, by the time I made it work, the interface and both classes still had to contain world and room, which was what I was trying to avoid. I did manage to keep from changing the tests, but with all this new unnecessary structure, I still had essentially the same issue that I was trying to avoid.

By this time, I knew that sunk costs in my tests, and an aversion to changing them, had resulted in code that was seriously more complex than the problem deserved. But I took the code to the Zoom Ensemble last night, to see whether there was at least some way that I hadn’t found to make the world and room appear only in the WorldImperative, not in the Simple one. My betters didn’t know a way to do that, but we did try a few things, all of which started creating cascading errors and irritating Kotlin by our mistakes. My mistakes.

We all agreed that the big mistake was trying to create this complex structure just to get out of editing a few tests. So, this morning, for my sins, I went through a long series of steps to back out the interface and its two implementations. The details are too tedious even for one of my articles. In the end, I got it done. There’s now just one Imperative and it is tested as it should be. We may have cause to review it in future articles. I just wanted to share that I had done a wrong thing and suffered for it.

In the end, changing the tests came down to two kinds of changes. In many instances, I had to replace a class name and add two parameters, and in a few instances I had to replace a comparison of two Imperatives with checks on the verb and noun. Fixing up the tests was the easiest part of what I had to do, and probably less than 1/20th of the total work. I went from A toB via about half the alphabet, when I could have just fixed the tests and been four hours ahead.

Along the way, I learned how to do multi-cursor edits in IDEA. Nice.

Don’t be like me. Don’t make a huge mess to avoid a little work. Find a way to make the work easier instead. Or just do it: it won’t be that bad.