I dream of Code

For much of this week and last, I have been preoccupied with fixing some code in the Pencilcase, the content management software I’ve been writing. I wanted to rework the way a particular sub-system works, but in doing, I managed to create quite the mess. No solution I came up with was both elegant and fully functional.
Last night, I slept like the dead. This morning, I cam into work, sat down, and essentially watched my fingers fly over the keyboard from afar as I quickly fixed the problem and completed the upgrad to the system.

Obviously, I figured out the solution in my sleep. What was interesting was that while I knew conciously this morning that I had a solution, I didn’t really know what it was. It was buried in my subconcious. I’ve essentially been in some odd trance all day writing code, not completely aware of what it was that I was writing. I just new it would work. After a lunch break, now reading over this same code, it really is quite elegent and simple. It’s a wonder I didn’t think of it sooner. It doesn’t even really require comments to explain, it’s so nice and simple. And most importantly? My code is shorter. I probably cut around 300 lines of code from the program moving to this upgrade. I’d already started moving towards a system where I didn’t need a special case for the root object, but now, that has been completely obviated. Before, where I had 3 collections of about 6 queries each to generate this menu, I now have 3 queries, one of which has an if/else within it. So much, much cleaner.