What does “level of indirection” mean in David Wheeler's aphorism?

后端 未结 2 2033
伪装坚强ぢ
伪装坚强ぢ 2020-12-23 09:55

I\'ve read this quote in a book:

There is no problem in computer science that can\'t be solved using another level of indirection.

相关标签:
2条回答
  • 2020-12-23 09:56

    One of the potential big advantages of indirection is reduced coupling. It's another way of saying that things should be compartmentalized appropriately. This often helps significantly with testing, maintainability, and flexibility over the long term.

    As an example, if your application needs to read some persisted data, instead of having the specific knowledge of where (and how) to read it scattered all throughout the application, you isolate it (put that reading of data into a method) and then let all of the other parts of your application call that method to get the data instead of each part of the app having to deal with those details itself.

    0 讨论(0)
  • 2020-12-23 10:06

    "Indirection" is using something that uses something else, in its broadest sense.

    So your example, using a pointer of a value instead of the value, fits this definition at one level. The pointer is the something and the value is the something else.

    Typically this is something larger in scope:

    • Using a web site to graphically display the data generated by an XML based service. Here the web site is the something and hiding behind it is the data which is the something else.
    • Using an operating system to access the display screen. Here are two layers, at least of indirection. The OS uses the screen driver. One something using a something else. Then the screen driver talks directly to the screen hardware causing it to make tiny dots of light here and there. The driver is the next something using the something else which is the hardware.
    • It is not uncommon for one API to deal with something on a high level and that API deals with the same thing on a lower level. Again a level of indirection is added on top of the low level API and we call it the new, improved API.

    This last example, perhaps, explains the "why" of it all.

    As we work with something we master it and learn how to abstract it to a higher level of abstraction, thus a new level of indirection is needed and we can solve bigger problems faster by offloading some of the work to the new API.

    0 讨论(0)
提交回复
热议问题