hidden pixel

Off-side Rule Information

A computer programming language is said to adhere to the off-side rule if the scope of declarations (a block) in that language is expressed by their indentation. The term and the idea are attributed to Peter J. Landin, and the term can be seen as a pun on the offside law of football (soccer).

Contents

Definition

Peter J. Landin, in an article called "The Next 700 Programming Languages", defined the off-side rule thus: "Any non-whitespace token to the left of the first such token on the previous line is taken to be the start of a new declaration."[1]

Code examples

The following is an example of indentation blocks in Python (note also the colons — they are obligatory, and not stylistic, in Python):[2]

def is_even(a):
if a % 2 == 0:
print('Even!')
return True
else:
print('Odd!')
return False

Alternatives

The primary alternative to delimiting blocks, popularized by C, is to ignore whitespace and mark blocks between curly braces { and }. An advantage of this is that nested block structure can be expressed on one line. A disadvantage is that a human reader of the code pays attention to indentation which does not have to follow the formal meaning that is communicated via the braces.

Lisp doesn't differentiate statements from expressions, and parentheses are enough to control the scoping of all statements within the language. As in curly bracket languages, whitespace is ignored.

Another alternative is for each block to begin and end with explicit keywords. Often, this means that newlines are important (unlike in curly bracket languages), but the indentation is not.

Examples of this rule are the Pascal convention of starting blocks with keyword "begin" and ending them with "end". In BASIC and FORTRAN, blocks begin with the block name (such as "IF") and end with the block name prepended with "END" (eg. "END IF"). The Bourne shell (sh, and bash) is similar, but the ending of the block is usually given by the name of the block written backwards (eg. "case" starts a conditional statement and it spans until the matching "esac". However, blocks beginning "do" end with "done").

Off-side rule languages

References

This article was originally based on material from the Free On-line Dictionary of Computing, which is licensed under the GFDL.

  1. ^ Landin, Peter J. (March 1966). "The next 700 programming languages". Communications of the ACM 9 (3): 157–166. doi:10.1145/365230.365257. http://web.archive.org/web/20070417160748/http://www.cs.utah.edu/~wilson/compilers/old/papers/p157-landin.pdf.
  2. ^ Python FAQ on colons
  3. ^ The Haskell Report - Layout
This programming language-related article is a stub. You can help Wikipedia by expanding it.
Types of programming languages
Array · Aspect-oriented · Assembly · Class-based · Compiled · Concatenative · Concurrent · Data-structured · Dataflow · Declarative · Domain-specific · Dynamic · Esoteric · Event-driven · Extensible · Functional · High-level · Imperative · Interpreted · Logic · Low-level · Machine · Macro · Metaprogramming · Multi-paradigm · Non-English-based · Object-based · Object-oriented · Off-side rule · Pipeline · Procedural · Prototype-based · Reflective · Rule-based · Scripting · Synchronous · Very high-level · Visual

Categories: Programming language topics

 

The above information uses material from Wikipedia and is licensed under the GNU Free Documentation License.
Some facts may not have been fully verified for accuracy. [Disclaimers]
This page was last archived by our server on Sun Jul 31 04:28:36 2011.
Displaying this page or its contents does not use any Wikimedia Foundation's resources.
The owners of this site proudly support the Wikimedia Foundation.