Details, Explanation and Meaning About Indentation

Indentation Guide, Meaning , Facts, Information and Description

An indentation can mean two things:

  • To make notches in something or form deep recesses in a coastline for instance.
  • To place text farther to the left to separate it from surrounding text.

For example, this is an indentation of one space:
Indented block
and this is an indentation of two spaces:
 Indented block 2

In the written form of many American and European languages, an indentation is used at the beginning of a line to signal the start of a new paragraph.

Indentation in programming

In computer programming languages, indentation is used to format source code in order to improve its readability. Indentation is generally only of use to programmers; compilers and interpreters rarely care how much whitespace is present inbetween programming statements. (Python is a notable exception to this rule.) Debates over where to indent, whether to use spaces or tabs, and how many spaces to use are often hotly debated among programmers, leading some to classify indentation as a religious war.

(The following is from The Jargon File, version 4.4.7)

There are four major indentation styles (which determine the number of spaces to indent and where to indent) for the C programming language, which is also used for other programming languages with syntaxes similar to that of C, notably Java and C++:

  • K&R; style — Named after Brian Kernighan and Dennis Ritchie because the examples in The C Programming Language are formatted this way. Also called kernel style because Unix kernel is written in it, and the 'One True Brace Style' (abbrev. 1TBS) by its partisans. In C code, the body is typically indented by eight spaces (or one tab) per level, as shown here. Four spaces are occasionally seen in C, but in C++ and Java four tends to be the rule rather than the exception.

() {
       
}

  • Allman style — Named for Eric Allman, a Berkeley hacker who wrote a lot of the BSD utilities in it (it is sometimes called BSD style). Resembles normal indent style in Pascal and Algol. It is the only style other than K&R in widespread use among Java programmers. Basic indent per level shown here is eight spaces, but four (or sometimes three) spaces are generally preferred by C++ and Java programmers.

if ()
{
       
}
  • Whitesmiths style — popularized by the examples that came with Whitesmiths C, an early commercial C compiler. Basic indent per level shown here is eight spaces, but four spaces are occasionally seen.

if ()
       {
       
       }

  • GNU style — Used throughout GNU EMACS and Free Software Foundation code, and just about nowhere else. Indents are always four spaces per level, with { and } halfway between the outer and inner indent levels.

if ()
 {
   
 }

Surveys have shown the Allman and Whitesmiths styles to be the most common, with about equal mind shares. K&R/1TBS used to be nearly universal, but is now much less common in C (the opening brace tends to get lost against the right paren of the guard part in an if or while, which is, in the words of the Jargon File, "a Bad Thing." Defenders of 1TBS argue that any putative gain in readability is less important than their style's relative economy with vertical space, which enables one to see more code on one's screen at once. The Java Language Specification legislates not only the capitalization of identifiers, but where nouns, adjectives, and verbs should be in method, class, interface, and variable names (section 6.8). While the specification stops short of also standardizing on a bracing style, all source code originating from Sun Laboratories uses the K&R style. This has set a precedent for Java programmers, which most follow.

External link


This is an Article on Indentation. Page Contains Information, Facts Details or Explanation Guide About Indentation


Google
 
Web www.E-paranoids.com

Search Anything