What does "orthogonality" mean when talking about programming languages? What are some examples of Orthogonality?
57.8k 29 29 gold badges 179 179 silver badges 238 238 bronze badges asked Oct 6, 2009 at 18:55 ahmet alp balkan ahmet alp balkan 44.7k 41 41 gold badges 146 146 silver badges 221 221 bronze badgesOrthogonality is the property that means "Changing A does not change B". An example of an orthogonal system would be a radio, where changing the station does not change the volume and vice-versa.
A non-orthogonal system would be like a helicopter where changing the speed can change the direction.
In programming languages this means that when you execute an instruction, nothing but that instruction happens (which is very important for debugging).
There is also a specific meaning when referring to instruction sets.
7,389 6 6 gold badges 51 51 silver badges 63 63 bronze badges answered Oct 6, 2009 at 19:01 31.7k 43 43 gold badges 149 149 silver badges 238 238 bronze badges This answer reminds me of "superposition" theory from signal and systems. Commented Jul 8, 2010 at 22:08A very clear explanation of the different usages of this word: c2.com/cgi/wiki?DefinitionOfOrthogonal
Commented Oct 7, 2012 at 16:13 So is functional programming completely orthogonal? Commented Oct 11, 2013 at 10:24That's an interesting question @yannbane. In theory, depending on the theoretical functional language, it may be true. In practice no, even functional languages have ways to change state.
Commented Oct 11, 2013 at 14:45 I bet that helicopter example is from "Pragmatic Programmer" :) Commented Aug 31, 2015 at 6:04answered Oct 6, 2009 at 19:01 Federico klez Culloca Federico klez Culloca 26.9k 17 17 gold badges 59 59 silver badges 99 99 bronze badgesOrthogonality is one of the most important properties that can help make even complex designs compact. In a purely orthogonal design, operations do not have side effects; each action (whether it's an API call, a macro invocation, or a language operation) changes just one thing without affecting others. There is one and only one way to change each property of whatever system you are controlling.
Think of it has being able to change one thing without having an unseen affect on another part.
answered Oct 6, 2009 at 19:02 Martin Beckett Martin Beckett 95.8k 28 28 gold badges 194 194 silver badges 266 266 bronze badgesBroadly, orthogonality is a relationship between two things such that they have minimal effect on each other.
The term comes from mathematics, where two vectors are orthogonal if they intersect at right angles.
Think about a typical 2 dimensional cartesian space (your typical grid with X/Y axes). Plot two lines: x=1 and y=1. The two lines are orthogonal. You can change x=1 by changing x, and this will have no effect on the other line, and vice versa.
In software, the term can be appropriately used in situations where you're talking about two parts of a system which behave independently of each other.
answered Oct 6, 2009 at 19:05 62.7k 6 6 gold badges 84 84 silver badges 93 93 bronze badges I believe this is the best answer written. Commented Aug 25, 2022 at 17:22If you have a set of constructs. A langauge is said to be orthogonal if it allows the programmer to mix these constructs freely. For example, in C you can't return an array(static array), C is said to be unorthognal in this case:
int[] fun(); // you can't return a static array. // Of course you can return a pointer, but the langauge allows passing arrays. // So, it is unorthognal in case.
answered Oct 6, 2009 at 19:03
Khaled Alshaya Khaled Alshaya
96.2k 41 41 gold badges 180 180 silver badges 236 236 bronze badges
Actually I saw this in my book and still don't understand what is that.
Commented Oct 6, 2009 at 19:08
LOL I'm using this book and saw this question on online quiz of the book. What a coincidence. Maybe I should read first chapter, too.
Commented Oct 6, 2009 at 19:21It's simply saying that return and arrays are more complex when put together: you can't use return around arrays without thinking about the interaction between them. Ideally, you would know what return means, and what an array is, and so you would know what returning an array would do, but actually, it's more complex than that, because C exposes implementation details about arrays (and return).
Commented Oct 6, 2009 at 22:22This sense of "orthogonal" is covered by: en.wikipedia.org/wiki/Orthogonality_(programming) , but it's a new page with little content.
Commented Oct 24, 2009 at 11:33This is the "more right" answer about orthogonality in context of programming. "orthogonality" means that a programming construct can be mixed with any other construct, and its semantics will still remain the same.
Commented Dec 3, 2015 at 8:25Most of the answers are very long-winded, and even obscure. The point is: if a tool is orthogonal, it can be added, replaced, or removed, in favor of better tools, without screwing everything else up.
It's the difference between a carpenter having a hammer and a saw, which can be used for hammering or sawing, or having some new-fangled hammer/saw combo, which is designed to saw wood, then hammer it together. Either will work for sawing and then hammering together, but if you get some task that requires sawing, but not hammering, then only the orthogonal tools will work. Likewise, if you need to screw instead of hammering, you won't need to throw away your saw, if it's orthogonal (not mixed up with) your hammer.
The classic example is unix command line tools: you have one tool for getting the contents of a disk (dd), another for filtering lines from the file (grep), another for writing those lines to a file (cat), etc. These can all be mixed and matched at will.
answered Oct 6, 2009 at 22:18 2,147 12 12 silver badges 16 16 bronze badgesWhile talking about project decisions on programming languages, orthogonality may be seen as how easy is for you to predict other things about that language for what you've seen in the past.
For instance, in one language you can have:
for splitting a string and
for getting the lenght.
On a language more orthogonal, you would always use str.x or x(str).
When you would clone an object or do anything else, you would know whether to use
That's one of the main points on programming languages being orthogonal. That avoids you to consult the manual or ask someone.
The wikipedia article talks more about orthogonality on complex designs or low level languages. As someone suggested above on a comment, the Sebesta book talks cleanly about orthogonality.
If I would use only one sentence, I would say that a programming language is orthogonal when its unknown parts act as expected based on what you've seen. Or. no surprises.
answered Oct 6, 2009 at 19:22 146 1 1 silver badge 7 7 bronze badgesThis answer isn't consistent to others; this just claims consistency between function calls or overall structure in contrast to others that are on the lines of "less-coupling" or "side-effectlessness".
Commented Jul 8, 2010 at 22:07This is the usage I usually have heard. I think the reason it is orthogonal is that if you have X.ToString and X.GetType, you can vary the object and the syntax is the same, or you can vary the function and the syntax is the same. The object is independent of the function.
Commented Dec 2, 2012 at 13:51From Robert W. Sebesta's "Concepts of Programming Languages":
312 3 3 silver badges 11 11 bronze badges answered Aug 15, 2015 at 22:09 Max Stephen Max Stephen 71 3 3 bronze badgesAs examples of the lack of orthogonality in a high-level language, consider the following rules and exceptions in C. Although C has two kinds of structured data types, arrays and records (structs), records can be returned from functions but arrays cannot. A member of a structure can be any data type except void or a structure of the same type. An array element can be any data type except void or a function. Parameters are passed by value, unless they are arrays, in which case they are, in effect, passed by reference (because the appearance of an array name without a subscript in a C program is interpreted to be the address of the array’s first element)
Orthogonality is a system design property facilitating feasibility and compactness of complex designs. Orthogonality guarantees that modifying the technical effect produced by a component of a system neither creates nor propagates side effects to other components of the system. The emergent behavior of a system consisting of components should be controlled strictly by formal definitions of its logic and not by side effects resulting from poor integration, i.e. non-orthogonal design of modules and interfaces. Orthogonality reduces testing and development time because it is easier to verify designs that neither cause side effects nor depend on them.
For example, a car has orthogonal components and controls (e.g. accelerating the vehicle does not influence anything else but the components involved exclusively with the acceleration function). On the other hand, a non-orthogonal design might have its steering influence its braking (e.g. electronic stability control), or its speed tweak its suspension.1 Consequently, this usage is seen to be derived from the use of orthogonal in mathematics: One may project a vector onto a subspace by projecting it onto each member of a set of basis vectors separately and adding the projections if and only if the basis vectors are mutually orthogonal.
An instruction set is said to be orthogonal if any instruction can use any register in any addressing mode. This terminology results from considering an instruction as a vector whose components are the instruction fields. One field identifies the registers to be operated upon, and another specifies the addressing mode. An orthogonal instruction set uniquely encodes all combinations of registers and addressing modes.
answered Oct 6, 2009 at 19:01 TheVillageIdiot TheVillageIdiot 40.4k 21 21 gold badges 134 134 silver badges 191 191 bronze badges Oh thanks I just visited this stub en.wikipedia.org/wiki/Orthogonality_%28programming%29 Sorry. Commented Oct 6, 2009 at 19:06"accelerating the vehicle does not influence anything else but the components involved exclusively with the acceleration function" is trivially false, e.g. the suspension reacts to acceleration, the total grip available is limited so acceleration affects cornering ability, it is almost a poster child for non-orthogonality. (good answer, bad example from real life)
Commented Jun 22, 2022 at 19:55Orthogonality is a system design property facilitating feasibility and compactness of complex designs. Orthogonality guarantees that modifying the technical effect produced by a component of a system neither creates nor propagates side effects to other components of the system. The emergent behavior of a system consisting of components should be controlled strictly by formal definitions of its logic and not by side effects resulting from poor integration, i.e. non-orthogonal design of modules and interfaces. Orthogonality reduces testing and development time because it is easier to verify designs that neither cause side effects nor depend on them.
For example, a car has orthogonal components and controls (e.g. accelerating the vehicle does not influence anything else but the components involved exclusively with the acceleration function). On the other hand, a non-orthogonal design might have its steering influence its braking (e.g. electronic stability control), or its speed tweak its suspension.[1] Consequently, this usage is seen to be derived from the use of orthogonal in mathematics: One may project a vector onto a subspace by projecting it onto each member of a set of basis vectors separately and adding the projections if and only if the basis vectors are mutually orthogonal.
An instruction set is said to be orthogonal if any instruction can use any register in any addressing mode. This terminology results from considering an instruction as a vector whose components are the instruction fields. One field identifies the registers to be operated upon, and another specifies the addressing mode. An orthogonal instruction set uniquely encodes all combinations of registers and addressing modes.
To put it in the simplest terms possible, two things are orthogonal if changing one has no effect upon the other.
answered Oct 6, 2009 at 19:03 Laurence Gonsalves Laurence Gonsalves 142k 36 36 gold badges 257 257 silver badges 305 305 bronze badgesOrthogonality means the degree to which language consists of a set of independent primitive constructs that can be combined as necessary to express a program. Features are orthogonal if there are no restrictions on how they may be combined
Example : non-orthogonality
PASCAL: functions can't return structured types. Functional Languages are highly orthogonal.
answered Dec 9, 2015 at 14:13 11 4 4 bronze badgesThere are a lot of answers already that explain what orthogonality generally is while specifying some made up examples. E.g. this answer explains it well. I wanted to provide (and gather) some real life examples of orthogonal or non-orthogonal features in programming languages:
In this case they write that modules are orthogonal to namespaces because a statement like import foo will not import the module-namespace related to foo :
import foo; // foo exports foo::bar() bar (); // Error foo::bar (); // Ok using namespace foo; bar (); // Ok
44.7k 41 41 gold badges 146 146 silver badges 221 221 bronze badges
answered Nov 5, 2020 at 15:23
2,271 22 22 silver badges 29 29 bronze badges
From Michael C. Feathers' book "Working Effectively With Legacy Code":
answered May 28, 2022 at 6:23 31 3 3 bronze badgesIf you want to change existing behavior in your code and there is exactly one place you have to go to make that change, you've got orthogonality.
In programming languages a programming language feature is said to be orthogonal if it is bounded with no restrictions (or exceptions). For example, in Pascal functions can't return structured types. This is a restriction on returning values from a function. Therefore we it is considered as a non-orthogonal feature. ;)
answered Nov 12, 2013 at 12:29 161 1 1 silver badge 2 2 bronze badgesOrthogonality in Programming:
answered Jan 18, 2014 at 12:28 14.2k 16 16 gold badges 79 79 silver badges 116 116 bronze badgesOrthogonality is an important concept, addressing how a relatively small number of components can be combined in a relatively small number of ways to get the desired results. It is associated with simplicity; the more orthogonal the design, the fewer exceptions. This makes it easier to learn, read and write programs in a programming language. The meaning of an orthogonal feature is independent of context; the key parameters are symmetry and consistency (for example, a pointer is an orthogonal concept).
Orthogonality in a programming language means that a relatively small set of primitive constructs can be combined in a relatively small number of ways to build the control and data structures of the language. Furthermore, every pos- sible combination of primitives is legal and meaningful. For example, consider data types. Suppose a language has four primitive data types (integer, float, double, and character) and two type operators (array and pointer). If the two type operators can be applied to themselves and the four primitive data types, a large number of data structures can be defined. The meaning of an orthogonal language feature is independent of the context of its appearance in a program. (the word orthogonal comes from the mathematical concept of orthogonal vectors, which are independent of each other.) Orthogonality follows from a symmetry of relationships among primi- tives. A lack of orthogonality leads to exceptions to the rules of the language. For example, in a programming language that supports pointers, it should be possible to define a pointer to point to any specific type defined in the language. However, if pointers are not allowed to point to arrays, many potentially useful user-defined data structures cannot be defined. We can illustrate the use of orthogonality as a design concept by compar- ing one aspect of the assembly languages of the IBM mainframe computers and the VAX series of minicomputers. We consider a single simple situation: adding two 32-bit integer values that reside in either memory or registers and replacing one of the two values with the sum. The IBM mainframes have two instructions for this purpose, which have the forms
A Reg1, memory_cell AR Reg1, Reg2
where Reg1 and Reg2 represent registers. The semantics of these are
Reg1 ← contents(Reg1) + contents(memory_cell) Reg1 ← contents(Reg1) + contents(Reg2)
The VAX addition instruction for 32-bit integer values is
ADDL operand_1, operand_2
whose semantics is
operand_2 ← contents(operand_1) + contents(operand_2)
In this case, either operand can be a register or a memory cell. The VAX instruction design is orthogonal in that a single instruction can use either registers or memory cells as the operands. There are two ways to specify operands, which can be combined in all possible ways. The IBM design is not orthogonal. Only two out of four operand combinations possibilities are legal, and the two require different instructions, A and AR . The IBM design is more restricted and therefore less writable. For example, you cannot add two values and store the sum in a memory location. Furthermore, the IBM design is more difficult to learn because of the restrictions and the additional instruction. Orthogonality is closely related to simplicity: The more orthogonal the design of a language, the fewer exceptions the language rules require. Fewer exceptions mean a higher degree of regularity in the design, which makes the language easier to learn, read, and understand. Anyone who has learned a sig- nificant part of the English language can testify to the difficulty of learning its many rule exceptions (for example, i before e except after c).