terrible code snarl
Saturday, April 7 2007
As I mentioned some weeks ago, I've built a very flexible DHTML-based questionnaire system that stores a wide range of information within a framework of only three or four MySQL tables. I've been able to take parts of this code and use it as the data entry system for an AJAXy calendaring system and as the visual re-sorting system for Tableform (my generalized MySQL database administration system).
More recently, though, I've had to contend with the issue of relating information in this questionnaire system to other tables in the database around it. The solution has been a certain amount of de-normalization, forking copies of new and altered data in some questionnaires to certain other tables where it can be better manipulated and related to other data.
Today I implemented a system of hidden columns in multi-part questionnaires, allowing data in the questionnaires to be kept in sync with the data in the related tables. Inside these hidden columns the questionnaire can store IDs of the rows of identical data in those related tables.
The code to get this working reliably ended up terrible snarl, and untangling it was how I spent my evening. The core of the questionnaire system is a set of fairly good, heavily-tested code, but at times today I felt like I was butchering it and compromising something that had once been beautiful. I suppose any truly functional system is a marvelous compromise across numerous parameters, but there was something about the sheer ponderousness of this beast as it is developing that sort of made me want to start all over from scratch. But how could I? Sure, there were clunky, embarrassing things in the code, and the aforementioned duplication of data is anything but ideal, but the result was a miracle of functionality. It's difficult to imagine I could have implemented a system of such complexity, flexibility, and functionality without having taken the path I had. And it's also beside the point; I'd traveled miles and now I'm here with something to show for it.
For linking purposes this article's URL is:feedback
previous | next