3 ms·
Here's a trick I discovered for working with bad code that used to help me a lot: treat it as an archaeological dig. Complicated bad programs usually evolve out
by gruseom 18y ago
Here's a trick I discovered for working with bad code that used to help me a lot: treat it as an archaeological dig. Complicated bad programs usually evolve out of simpler bad programs, often in a semi-consistent way - inconsistent enough to be a maintenance nightmare, but consistent enough for a human reader to grok the patterns. If you can read the code backwards in this way and find the remains of the original simpler system, you then have a model for understanding the whole system: it's the crappy simple original one plus the crappy ways it was extended.
For example, complex bad systems are often extended by means of duplication (C-c-C-v-driven development). It's often possible, when you have a number of duplicated sections, to figure out which was the master and which the copies - e.g. if there were any comments in the original code, people will just leave them in the duplicated code. (The sort of programmer who reads and updates comments probably doesn't program by C-c-C-v in the first place.)
This brings up another point about bad code. Naive bad code is a lot easier to understand than sophisticated bad code. It's bloated and buggy, but there's always a sort of internal order to it. Bad programmers are able to maintain it by remembering the 10 places that X is done and the 19 places that Y is done. Sophisticated bad code, on the other hand - the kind full of impenetrable pseudo-abstraction - is a different can of worms. I don't think the above techniques apply to it. However, naive bad code is more common.
- LogicHoleFlaw 18y ago(C-c-C-v-driven development) I like to refer to this kind of programming as the successor to spaghetti code: copypasta.