HubHip: Computers: Programming: Languages: Off-side Rule (2)

DescriptionThis category involves one means by which different programming languages, within program code, control the scope of declarations, have blocks, how such start and end, and are: marked, formed, shown, expressed, indicated, denoted; their span.

Some programming languages obey the off-side rule: blocks are shown by their indentation, the whitespace that precedes them. The term was invented and named by Peter J. Landin in "The Next 700 Programming Languages", CACM vol 9 pp 157-165, March 1966: "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."

Off-side Rule language families: ISWIM, an abstract language that introduced the rule in 1966; ABC, Python; Miranda, Haskell, Curry; Occam; Pliant.

Alternatives:

The main alternative is paired symbols or keywords. Most programming languages use this means to mark blocks.

C-syntax family: whitespace is ignored. Blocks are marked between curly braces { and }. Advantage: code can be reformatted and neatly indented, even automatically, with no fear of change to block structure. Disadvantage: human readers see indentation easily and quickly and often miss much formal meaning communicated in braces, unless they are very careful.

Pascal family: blocks shown by keywords, start with "begin", end with "end".

LISP family: doesn't differentiate statements from expressions, parentheses are enough.

POSIX shell family: blocks start after each control keyword and end with the keyword written backwards: "case" starts conditional statements, "esac" ends them.


   Off-side Rule

Last update: 2008-05-05 14:46:45 Off-side Rule | Copyright 2008 HubHip.com