This articleneeds additional citations forverification.(February 2022) |
Incomputer programming,anindirection(also called areference) is a way of referring to something using a name, reference, or container instead of the value itself. The most common form of indirection is the act of manipulating a value through itsmemory address.For example, accessing avariablethrough the use of apointer.A stored pointer that exists to provide a reference to an object by double indirection is called anindirection node.In some older computer architectures, indirect words supported a variety of more-or-less complicatedaddressing modes.
Another important example is thedomain name systemwhich enables names such asen.wikipedia.org
to be used in place
of network addresses such as208.80.154.224
.The indirection from human-readable names to network addresses means that the references to a web page become more memorable, and links do not need to change when a web site is relocated to a different server.
Overview
editA famousaphorismofButler Lampsonthat is attributed toDavid Wheelergoes: "All problems in computer science can be solved by another level of indirection" (the "fundamental theorem of software engineering").[1] This is often deliberately mis-quoted[by whom?]with "abstraction layer"substituted for" level of indirection ". Acorollaryto this aphorism, and the original conclusion from Wheeler, is "...except for the problem of too many layers of indirection."
Ahumorous Internet memorandum,RFC1925,insists that:
(6) It is easier to move a problem around (for example, by moving the problem to a different part of the overallnetwork architecture) than it is to solve it.
- (6a) (corollary). It is always possible to add another level of indirection.
Object-oriented programmingmakes use of indirection extensively, a simple example beingdynamic dispatch.Higher-level examples of indirection are thedesign patternsof theproxyand theproxy server.Delegationis another classic example of an indirection pattern. Instrongly typedinterpreted languageswith dynamicdata types,most variable references require a level of indirection: first the type of the variable is checked for safety, and then the pointer to the actual value is dereferenced and acted on.
Recursive data typesare usually implemented using indirection, because otherwise if a value of a data type can contain the entirety of another value of the same data type, there is no limit to the size a value of this data type could need.
When doing symbolic programming from a formal mathematical specification the use of indirection can be quite helpful. To start with a simple example the variablesx,yandzin an equation such ascan refer to any number. One could imagine objects for various numbers and thenx,yandzcould point to the specific numbers being used for a particular problem. The simple example has its limitation as there are infinitely many real numbers. In various other parts of symbolic programming there are only so many symbols. So to move on to a more significant example, in logic the formulaαcan refer to any formula, so it could beβ,γ,δ,... orη→π,ς∨σ,... Whenset-builder notationis employed the statement Δ={α} means the set of all formulae — so although the reference is toαthere are two levels of indirection here, the first to the set of allαand then the second to a specific formula for each occurrence ofαin the set Δ.
See also
editReferences
edit- ^Spinellis, Diomidis (2007). "Another level of indirection". In Oram, Andy; Wilson, Greg (eds.).Beautiful Code: Leading Programmers Explain How They Think.Sebastopol, California: O'Reilly and Associates. pp. 279–291.