How do I avoid the Second System Effect?
danudey: The method I use is to look at the old functionality, figure out the structure, and rebuild it. Don't build a second system, build the first system better.In my scripts and projects, I generally start out with a simple, procedural batch of code, hacking on bits as I go. Eventually, I get to the point where code flow is nearly impossible to understand - too convoluted, too many global variables, function calls nested too deep, etc.Once I'm at that point, I usually know what the program is going to do and how it should do it, so I rewrite it in a more object-oriented manner. I don't add functionality, I just move it around to make more sense. I implement only the features that were in the code already, usually using as much of the old code as I can, but restructuring it in a way that makes more logical sense. When possible, I take out code I wasn't using.After that, I can build on the code further, extending it as needs warrant, until the code flow gets more complicated. Then I go back and refactor again.I find that if done properly, each iteration happens sooner (it's easier for larger and more complicated code bases to become inscrutable), but that each refactor becomes simpler (as you work towards an optimized design).