Off-side rule

From Wikipedia, the free encyclopedia

A computer programming language is said to adhere to the off-side rule if in it the scope of declarations (a statement block) is expressed by their indentation, i.e., blocks are formed (indicated) via 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 soccer.

Contents

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.

Peter J. Landin ,  "The Next 700 Programming Languages"[1]

The following is an example of indentation blocks in Python (note also the obligatory colons — they are merely syntactical markers to make it easier to read) [1]:

def is_even(a):
    if a / 2.0 == a / 2:
        return True
    else:
        return False

The way popularized by C is to ignore whitespace and mark blocks between curly braces { and }. An advantage of this is that program code can be automatically reformatted and neatly indented without fear of the block structure changing. A disadvantage is that a human reader of the code pays attention to indentation and might miss the formal meaning that is communicated with braces.

Lisp doesn't differentiate statements from expressions, and parentheses are enough to control the scoping of all statements within the language. Like 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, 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").

  1. ^ Landin, Peter J. (March 1966). "The next 700 programming languages". Communications of the ACM 9 (3): 157–166. DOI:10.1145/365230.365257.
Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.