David Wheeler: Any problem in computer science can be solved by another layer of indirection.
I am increasingly finding this to be very true. Why?
My own understanding in reality is:
- The code written initially is to solve a specific problem, so it is only targeted at specific situations.
- Gradually, there are more and more specific situations, and if we modify the original code, it becomes more and more complex and difficult to modify.
- In order to narrow down the problem, we can abstract the lowest level (the code that solves the specific problem initially), expose interface definitions, and adapt them at the upper level. The upper level adaptation is to adapt different types of specific problems to the lower level interface, which is equivalent to adding another layer.
- What are the benefits of step 3? The lower-level code requires fewer modifications, and the upper-level adaptation only involves adaptation logic. This achieves code isolation and reduces mutual influence. If there is a problem with the adaptation at this layer, as mentioned in step 2, we continue with step 3, adding another layer. This way, one problem after another can be solved layer by layer.
- Reality is very similar to this logic. Initially, the code is written in a rigid manner, and the more it is modified, the more difficult it becomes to modify. So we extract parameters and configurations to allow for more flexible configurations.
Just a small insight, but it is indeed true.