Zen & The Art of Code Maintenance January 30th, 2008
I've been neglecting my blog lately. The primary reason for this is that I've been busy and scattered across multiple projects, both physical and code, and typically during a spell like this I'm less contemplative. Anyhow, I've been back at code this last week and a half - not working on Font Fiend or ASJ 41 which are my announced projects but the other game that I have planned for this year. Another financial simulator is in the works here and I've found myself consumed by it lately. I had the idea for this game last summer at the lake and, off and on, I've been working on the design for about six months. A month or so ago my dad was pretty sick so I was crashing at his place for a few nights and that was a good time to work on this design because I only had the laptop and wasn't actively coding - just noodling with graphics and design ideas. At that point I kind of hit a wall because the game was too statistical - only an accountant who loves the columns would have liked that game. However, the last day at dads I had a breakthrough and came up with some good ideas for how to simplify the game play and I felt like I was off and running again. I've subsequently hit another wall where I realized that even that design was to complex and have further refined the game play. With this design background I've spent the past ten days banging out more code than renovations.
What's interesting about this is that I'm enjoying the actual coding of the game far more than I usually do - usually my favorite part is dreaming up a new game. But this time I'm finding that the actual moment to moment coding of the beast is very satisfying. I'm attributing this to the fact that I spent some time last year looking at and thinking about how I write code. I wanted a code process that was easier to pick up and put down - more modular - and along with this, something easier to just add new code chunks to. I thought this would require a grand new paradigm, a fancy WYSIWYG editor and all the rest... but what it really took was a few simple nudges to the way I have coded for just about forever. I took apart my finite state machine code and made it simpler to add new states, each of which have a service, construction and destruction function along with a text name so that I can bring up a browser at any point and readily jump from state to state. Since states within my FSM sometimes require a certain game variable state this does mean that I occasionally build a 'setup helper' state for test purposes but this simple modification has made it much easier for me to think of my code in terms of being independent modules. I also spent a week and moved over all of my string handling code to be completely unicode based, including writing a bunch of string handling code so that porting my games would not rely upon Microsoft string functions which might not be available on other computers. This simplified some code and also clarified the model under which I add text to my games - this was as much a matter of code cleanup as sitting down once and for all and committing to a text model so that when I think about what is going on with any of my programs game it is easier to grasp. This might seem simple and obvious but since I am dealing with libraries that I wrote a decade ago there was some inertia to letting go of some code and porting processes for devices which, realistically, I'm not going to support anymore
anyhow. Typically I add text to my programs with an independent text file filled with tags and text string pairs for easy language translation, since the code cleanup I turfed a bunch of 8 & 16 bit code in favor of always expecting the text file to be a 16-bit unicode file. My last process change is, frankly, almost embarrassing to admit. I'm not a guy that enjoys going back and cleaning up my code - but I write code as if I am. This includes a very sloppy habit of letting my file modules become unwieldy because I don't subdivide them very often (read never) which has the very bad side effect of making projects hard to step back into as time goes by as finding code becomes harder. All of this little nudges along with the cleaner FSM model and a design that feels really solid has made it really easy for me to be very in the moment for long stretches of time during the physical act of entering code into the machine.
Lastly, and this is not a code thing but something that has really increased my enjoyment of the process, I have been using Font Fiend, Icon Workshop and purchasing stock photography from Fotolio.com to create better looking demo art to hand off to Matthew once I have seen that a design idea has gelled into useful code. On it's face this change doesn't have much to do with the practicality of getting projects done because one way or the other Matthew ends up touching up most or all of the graphics... but it does. There are two reasons for this. The first is that it changes my mind set from one that says the UI work I am doing is going to be in flux until Matthew is done - this has the side effect of letting my be lax about UI cleanup on first pass because I work under the assumption that I will be coming back and doing rework anyhow. The second, related to the first, is that because I'm dealing with prettier graphics during my mockup phase I can have faith that code refinement that I am doing during the mockup phase is more likely to stick. This causes less rework and rework is costly not only because you are going back and doing work again but also because there is typically so much code in a game that you can't carry around all of the code in your head during development so going back to code costs you not only the work to redo but a substantial amount of time to re-immerse in code that you haven't touched in a few months.
Anyhow. Renovations are going slowly this week as the computer keeps pulling me back in. Hopefully I'll have a demo. to share soon enough. I've also promised a playable demo of ASJ which is currently in a state with a roughed out shell and a game model that shouldn't take months to make playable so that's got to happen in the coming weeks as well. Remind me to post a review of the Asus EEE that I bought last week, I'm not one prone to device lust but this is one sweet bit of kit.