Programming lessWednesday, November 28, 2007 by Dave Winer. A programming lesson I keep relearning. The design of the central data structure of an app determines the quality of the app, in every way. Any extra thought that goes into this, will pay off in: 1. Maintainability of the code. 2. Size of the code (you'll write less code with a well thought-out central data structure). 3. Simplicity of the user interface (the structure inevitably shows through in the UI). 4. Ability to respond to feature requests. 5. Adapt to new hardware, OS changes, other apps. 6. More "it just works" experiences. This is why it's sometimes the right thing to start over from scratch. Programmers often want to start over because they look at the code and it looks complicated, and they think they can make it simpler if they start over. They're right, of course, it will be simpler when they start over, because it won't do nearly as much as the mature product does. Once they finish building out the feature set, it may well be just as complicated. It's a judgement call. I remember looking at the source of Unix kernel for the first time as a grad student in Wisconsin, and being amazed at the simplicity and obviousness of the code. I couldn't believe something so simple actually worked. Your code at its kernel level must have this simplicity. But at the edges, where you're accomdating the minds of users, inevitably it gets a little messy. The key thing to look for is how hard is it to add a completely new feature. It should be easy to do that. If it's not, it's likely because of a poorly organized (and therefore not well-understood) central data structure. I've rewritten apps many times, over many years, because when I wrote the first or second versions, I didn't understand the problem well enough, and the code had turned into a morass of patches and workarounds. Right now I'm recoding the internals of a special-purpose aggregator. I've written many of these, over the years, always quickly, trying to get something running fast, and then lived with data structures that resulted. This time I'm going slowly and carefully, with an installed base of one (me) and ripping up the pavement whenever I find even a slightly better way of doing something. I have other users who are waiting, but that's life. 5/7/97: "When a programmer catches fire it's because he or she groks the system, its underlying truth has been revealed." |