What is the orthogonality?

Asked

Viewed 5,647 times

37

Within the context of software development what it means to be orthogonal?

Why it’s important to follow him?

5 answers

41


Something is orthogonal in relation to something else if changing something in it will not affect anything in other things. There is no dependency relationship.

It is very important to seek orthogonality whenever possible. Imagine if a car changed direction when you accelerate. Bad, right? In the car the throttle and steering wheel are orthogonal. Already in a helicopter they could not do that and to increase the speed it has to compensate other controls to keep the helicopter stable.

We can also talk about side effect. If your code does something watertight, only related to itself, it is orthogonal, has no side effects. If you have to worry about what will happen in other places when something changes in it then it is not orthogonal.

What is not DRY is not orthogonal. If you have not applied this principle, when you change in one place you have to change in your repetitions.

Orthogonality is related not exclusively to the principle of SRP.

A programming language is one of the most complicated things to do because much is not orthogonal. Each Feature works well on its own, but along with all the others has a lot of complication when there is intersection. When the Features can be used together without restrictions and complications she is orthogonal.

It is important to manage complexity, facilitate maintenance and reduce the need for testing.

  • was needing to ask a question related to the side effect (side-Effect) just this week.

  • @durtto if he didn’t answer, with what you have here, send see.

9

In software development the definition of orthogonality is exactly the same as the one used in the mathematical field.

In algebra, it is said to be orthogonal when two magnitudes have the scalar (or inner) product equal to zero, xy = 0. The calculation of the scalar product may be summarised as follows: xy = x y cosθ, where θ is the smallest angle between the two magnitudes. For non-zero quantities, it is said to be orthogonal only when cosθ is 0, which implies θ equal to 90º. That is why, when considered only two quantities, the concept of orthogonality and perpedicularity end up being mixed.

When treated with vectors, one can also calculate how much the quantity of one vector influences the quantity of another, that is, one calculates the projection of one greatness over the other and this calculation can be done through pRoj = |p| cosθ, where θ is again the smallest angle between the quantities.

Thus, if two magnitudes are orthogonal, it is known that cosθ will be null and, consequently, the projection of greatness on the other will also be null.

In less technical terms, this implies that one can change the magnitude of one of the magnitudes without changing the magnitude of the other orthogonal magnitudes to it.

When related to software development, one can translate the definition to how each part of the code does not have projection on the other parts, that is, when one part undergoes change, the other parts of the system will not be affected. When parts are not orthogonal, the projection of one on the other is non-zero and therefore any change made in one must be taken care about how it will impact the other.

Seeking to develop "orthogonality-oriented" has several positive consequences, such as ease of maintenance, since a code unit being orthogonal to the rest of the application can be changed without worrying about how the changes will impact the entire application, provided that orthogonality is maintained.

For a more practical visualization, we can imagine a greatness in X and another in Y, orthogonal to each other, producing, together, the red greatness. It is possible to change the quantities X and Y individually (through the ranges) without affecting the other in a way to alter the result as desired.

const canvas = document.querySelector('canvas');
const context = canvas.getContext('2d');
const x = document.getElementsByName('x')[0];
const y = document.getElementsByName('y')[0];

function update() {

  context.clearRect(0, 0, canvas.width, canvas.height);

  // Desenha o eixo X:
  context.beginPath();
  context.moveTo(0, 300);
  context.lineTo(x.value, 300);
  context.lineWidth = 5;
  context.stroke();

  context.beginPath();
  context.moveTo(0, 300);
  context.lineTo(0, 300 - y.value);
  context.lineWidth = 5;
  context.stroke();

  context.beginPath();
  context.moveTo(0, 300);
  context.lineTo(x.value, 300 - y.value);
  context.strokeStyle = "#FF0000";
  context.lineWidth = 5;
  context.stroke();

  context.strokeStyle = "#000000";
}

x.addEventListener('change', update);
y.addEventListener('change', update);

update();
.half {
  width: 50%;
  float: left;
}

canvas {
  border: 1px solid black;
}
<div class="half">
  <div>
    <label>X: <input type="range" name="x" value="100" min="0" max="300"></label>
  </div>
  <div>
    <label>Y: <input type="range" name="y" value="100" min="0" max="300"></label>
  </div>
</div>

<div class="half">
  <canvas width="300" height="300"></canvas>
</div>

4

In programming language, orthogonality means that a relatively small set of primitive constructions can be combined in a small number of ways to construct the control and data structures of a language.

In practice, an orthogonal language would be easier to learn and would have fewer exceptions. Because every exception is a construction that needs to be learned to be avoided. Some examples of lack of orthogonality (classics) in C:

  • A struct can be return values of a function, but vectors nay.
  • A vector can be return value if it is encapsulated by a struct
  • A member of a struct can be any type of data except void or a struct of the same type.
  • A vector can be of any type except void.
  • All data types are passed by value except vectors

On the other hand, the excess orthogonality is harmful:

  • All instructions ( including assignments, if, while, etc) return values and can be used in expressions.
  • Logical and arithmetic operations may appear mixed.

-1

ORTHOGONALITY

• A relatively small set of constructions primitive can be combined, in a relatively small ways, to build the control structure and language data

• The meaning of an orthogonal language resource is free context of its appearance in a program

Importance

• Makes language easier to learn

• Decreases programming constraints

• Too much orthogonality can also cause problems

• Simplicity

- Combination of a relatively small number of primitive constructions

- Limited use of the concept of orthogonality edisciplinas.usp.br/pluginfile.php/1957769/mod_resource/content/3/Languages%20de%20Programming%20-%202014%20aula1.pdf

-2

In computer science, orthogonality in programming language design is the ability to use various language resources in arbitrary combinations with consistent results. The number of independent primitive concepts has been minimized so that the language is easy to describe, learn and implement. On the other hand, these concepts were applied "orthogonally" in order to maximize the expressive power of the language while trying to avoid deleterious superfluities. REF.: https://en.wikipedia.org/wiki/Orthogonality

  • 2

    "in arbitrary combinations with consistent results, "can you elaborate on that part better? That statement was very confusing. And what are "primitive independent concepts"? And what would be "deleterious superfluities"?

  • 1

    Sorry, @Woss. The translation may have been a little deficient compared to the original text. Original text: "Orthogonality in Programming language design is the Ability to use Various language Features in arbitrary Combinations with consistent Results".

Browser other questions tagged

You are not signed in. Login or sign up in order to post.