When people look at what they want to call Legacy Code, they don’t see a coherent system. They see an implementation that they can’t read. They see a design that is not simple/elegant enough. They see a pile of patches instead of a clean architecture. They wonder how any competent programmer could have made such a mess.
They soon decide that “Legacy Code” is bad code and possibly even bad design.
Initial Knowledge
When you start building a project, you know the least about it you ever will. As soon as we begin working on a project, we learn. Part of that learning is just digging further into the details. Sometimes our initial assumptions will be supported by the details we’ve learned. Often, we find that we didn’t understand what we thought we did.
Now, we have a choice. We can continue in what we now know is the wrong direction, or we can modify our understanding and build something different than we planned.
The longer we spend building the system, the more we will deviate from the simple, elegant design we started with. However, since we understand why we made these changes, we are learning. Hopefully, the result will be good, even though we couldn’t have imagined where we will end up at the time we began.
Early Decisions
Any decisions you make early on are based on flawed information. The initial decisions will be made with the least information. Any information we have is flawed, because the understanding we based it on is incomplete.
These early decisions are practically guaranteed to result in code we will need to rework or work around later. As we realize that we’ve gone the wrong direction, we’ll need to modify the implementation based on what we now know.
Changes Are Coming
Even good decisions and clean implementation can be overwhelmed by changes in environment. The environment in which we are building the system is subject to change. Hardware or software we depend on will be replaced, the goals of the business may change, any legal requirements for the system may also be changed.
Even if we did a perfect job with our initial design (which we’ve seen is very unlikely), and implemented everything perfectly (also a problematic assumption), it is almost certain that there will be changes in the environment.
Hindsight
In hindsight, many reasonable decisions look like bad ones. Between imperfect knowledge up front and changes outside your control, any decision we make will eventually look sub-optimal. The best of intentions and the best skills will not prevent this.
In the end, the new system ends up looking a lot like a legacy system. And it happens more quickly than you might think.