Dear programmer,
The majority of code in existence is one or more of:
- Duplicated
- Buggy
- Confusing
- Poorly Named
- Overly verbose
- Inefficient
You need to learn to be comfortable and effective working with “bad” code, because thats the most common kind.
(Also, code that is written to different styles & conventions than your own can appear worse than it really is.)
An inability to stomach bad code can lead to:
- Obsession with code and design aesthetics of little practical impact
- Scrapping code when it becomes ugly or or stressed, and thus losing the value in it
- Difficulty making forward progress on legacy code without first refactoring it
Why is code normally bad?
The obvious explanation is the limitations and imperfections of human programers.
But I think there is a second, more innate cause.
As any system evolves, the assumptions under which code was written change, and the code & design needs to stretch. As a system grows, code duplicates and the copies diverge. Bugs emerge The system becomes stressed, and it requires active effort, in the form of refactoring, testing and bug investigation, to catch bugs, relieve stress, and factor out the duplication.
However, this effort costs money and/or time. This money/time is often better spent on adding new features. If code is really ugly, it may make sense to refactor, but refactoring can quickly incur higher costs than benefits. Thus, much mature code exists in a perpetual state of mild ugliness and design stress. The codebase hovers just under the “fix threshold”, in a zone where the cost/benefit ratio of removing its imperfections cannot compete against the value of additional new features.
If we programmers are going to inhabit such a world, we better get comfortable and learn to love, or at least tolerate, the flaws of the inhabitants.