In my last entry I intimated that software, at the object level, had no real structure, and that this was the root of most of the problem in programming today. I’m sure this is a rather puzzling statement, as other than adding data members to a class, what kind of structure could you have for a class?
Before I go there, I want to detour slightly into some light theory. The most fundamental principle of the science in computer science could probably be stated this way: Don’t repeat yourself.
Its the principle of parsimony and Occam’s razor. Programmers quickly gain the skill of slapping repeated code chunks into one place and making it a subroutine – otherwise you don’t get out of Coding 101. In Computer Softese, this activity is known as factoring, or in the case of data, normalization. It all comes down to the same basic concept.
However, the kinds of stuff that typically gets factored is the behavior code – the code that does stuff – actions, operations etc. So what other kind of code is there? To quote our President, there is the “decider” code.
Strung throughout the “Actions” in the software are the conditional statements that evaluate the state of the nation and choose a codepath for the instruction pointer to travel. This decider code is the true nervous system for software – it continually tests its environment and activates appropriate activity in response to what it discovers. To put it another way, this conditional logic is the “brains” of software – the rest, the activity code – is the “brawn”.
Underlying the actual code is the logical “idea” of what the software should be doing – the experience it is really trying to deliver. This abstract ideal is, in fact, the most critical part because it is the actual point of the whole endeavour. But this fact remains obscure due to its format – a bunch of Boolean tests strung throughout the code each heading up a lot of code branches. So despite its primary importance as the most critical part of our software, it remains the portion that no one actually tries to normalize – that is apply computer science to!
We can describe this logical idea of the software as its set of “modes”. The Boolean conditionals are actually testing the raw data of the system to discover what mode the software is in, and then doing some activity based on that discovery. This is all fine. The problem emerges, the denormalization that is, when these same tests are done over and over again throughout the codebase. How can this happen? By being the typical and simplest (but not best) way to build out an API. And it is almost mandated in a complex, multilevel object-oriented class.
I’ll pick up on that next time.
