Orthogonality (programming)

Orthogonality (programming)

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. The term is most frequently used with regards to assembly instruction sets, as orthogonal instruction set.

Orthogonality Concept

Orthogonality is a very important concept. It addresses how relatively small number of components that can be combined in a relatively small number of ways to get the desired results. It is closely associated with simplicity: the more orthogonal the design the fewer exceptions and it makes it easier to learn, read, and write programs in a programming language. The meaning of an orthogonal feature is independent of the context. The key parameters are symmetry and consistency. For example pointers is an orthogonal concept.

Here is one example from IBM Mainframe and VAX that highlights this concept. In IBM main frame has two different instructions for adding the contents of a register to a memory cell or another register. These statements are shown below:

A Reg1, memory_cell
AR Reg1, Reg2

In the first case, contents of Reg1 are added to the contents of a memory cell and the result is stored in Reg1; in the second case contents of Reg1 are added to the contents of another register (Reg2) and the result is stored in Reg1.

In contrast to the above set of statement, VAX has only one statement for addition as shown below:

ADDL operand1, operand2

In this case the two operands, operand1 and operand2, can be registers, memory cells, or a combination of both and the instruction simply adds the contents of operand1 to the contents of operand2 and store the result in operand1.

It can be easily seen that the VAX’s instruction for addition is more orthogonal than the instructions provided by IBM and hence it is easier for the programmer to remember and use it as compared to the one provided by IBM.

Let us now study the design of C language from the perspective of orthogonality. We can easily see that C language is not very consistent in its treatment of different concepts and language structure and hence makes it difficult for the user to learn and use the language. Here are a few examples of exceptions:

• You can return structures but not arrays from a function • An array can be returned if it is inside a structure • A member of a structure can be any data type except void or the structure of the same type • An array element can be any data type except void • Everything is passed by value except arrays • void can be used as type in a structure but you cannot declare a variable of this type in a function.

Orthogonality The Other side

Too much orthogonality is also troublesome. Let us again have a look at C language and try to understand this concept:

In C Language

  • All statements (including assignment, if, while, etc) return some value and hence can be used in expressions.
  • Logic and arithmetic expressions can be intermixed.

This can cause side effects and cryptic code.

Since languages need large number of components, too much orthogonality can cause problems. From a language designer’s point of view, the most difficult task is to strike a balance which obviously is not trivial.

Links


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Orthogonality — The line segments AB and CD are orthogonal to each other. Orthogonality occurs when two things can vary independently, they are uncorrelated, or they are perpendicular. Contents 1 Mathematics …   Wikipedia

  • Class (computer programming) — In object oriented programming, a class is a construct that is used as a blueprint to create instances of itself – referred to as class instances, class objects, instance objects or simply objects. A class defines constituent members which enable …   Wikipedia

  • Magic (programming) — In the context of computer programming, magic is an informal term for abstraction it is used to describe code that handles complex tasks while hiding that complexity to present a simple interface. The term is somewhat tongue in cheek and carries… …   Wikipedia

  • ABC (programming language) — Infobox programming language name = ABC paradigm = multi paradigm: imperative, procedural, structured year = designer = Leo Geurts, Lambert Meertens, Steven Pemberton developer = CWI latest release version = 1.05.02 latest release date = typing …   Wikipedia

  • List of object-oriented programming terms — Those words found in object oriented programming. Some are related to OOP and some not. A * Abstract class (also called deferred class) * Abstract method * Abstraction (computer science) * Access control * Accessor method * Allocated class *… …   Wikipedia

  • Cecil (programming language) — Cecil is a pure object oriented programming language that was developed by Craig Chambers at the University of Washington in 1992 to be part of the Vortex project there. Cecil has many similarities to other object oriented programming languages,… …   Wikipedia

  • PDP-11 — This article is about the PDP 11 series of minicomputers. For the PDP 11 processor architecture, see PDP 11 architecture. The PDP 11 was a series of 16 bit minicomputers sold by Digital Equipment Corporation (DEC) from 1970 into the 1990s, one of …   Wikipedia

  • FOSD origami — Feature Oriented Programming or Feature Oriented Software Development (FOSD) is a general paradigm for program synthesis in software product lines. Please read the Feature Oriented Programming page that explains how an FOSD model of a domain is a …   Wikipedia

  • Don't repeat yourself — In software engineering, Don t Repeat Yourself (DRY) or Duplication Is Evil[citation needed] (DIE) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi tier architectures. The …   Wikipedia

  • MOS Technology 6502 — The MOS Technology 6502 is an 8 bit microprocessor that was designed by Chuck Peddle for MOS Technology in 1975. When it was introduced, it was the least expensive full featured CPU on the market by a considerable margin, costing less than one… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”