Captain's Log: Stardate 77722.1

The last few days I've made a ton of progress on a major refactor to Anukari's data model implementation. It had accumulated a fair bit of technical debt, mostly with some quick hacks using macros where templates would work better, but also some stuff where the way the code was organized was not super well-thought-out. The macro hacks were great because they prevented a ton of code duplication, but while they were appropriate when the data model was 1k lines of code, they got unwieldy by the time it was 10k lines of code.

Now all the macros are gone, and the code de-duplication is done with some fairly clever template stuff. The tricky bit is that for efficiency (as well as readability) there are a bunch of things that need to be done with static types. But I found a way to use the "curiously reoccurring template pattern" to make that work in a very nice way. The difficult work is now done, and now I just need to do a bunch of cleanups before I can go back to feature work.

I didn't really plan to do this refactoring this week, but when I sat down to really think through how I wanted the overall MIDI routing to work (notes, CC, pitch bend, pressure, aftertouch), I realized that using the existing paradigm to implement it would just dig me in a lot deeper to the problems I had already created. So it made sense to finally yank the band-aid and do the work to factor things in a better way. I'm looking forward to approaching the MIDI routing again, and am hopeful that it will be much simpler than what I was imagining before.

One thing worth mentioning is there's no way I could have pulled off this refactoring without the test coverage that I built out earlier this year. So far the refactor has touched something like 15k lines of code, and a lot of that is big regex search-and-replace things, and other nontrivial bulk changes, and it's in the most core part of the code. In doing it I definitely introduced some extremely subtle bugs, but the tests caught them and they were easy to track down because I ran the tests frequently, so I didn't have many changes to look at for where the bugs came from. Seeing the 80 golden tests pass, as well as all the fuzz tests, gives me immense confidence that I haven't broken anything important. I wouldn't have done this kind of refactor without that backup.


© 2024 Anukari LLC, All Rights Reserved
Contact Us|Legal