1TBS ⇝

indent style

<programming>

Rules for formatting code to make it easier to visually match up the beginning and end of a block of statements, particularly one controlled by a control statement such as "if", "else", "for", "while", "do". This becomes important with large, nested blocks of code.

The C programming language's four indent styles vary in the placement of "" and "" with respect to the statement(s) they enclose and the controlling statement.

"Allman style" is named after Eric Allman, a Berkeley hacker who wrote many BSD utilities in it. It is sometimes called "BSD style". It resembles normal indent style in Pascal and ALGOL. Basic indent per level is eight or four spaces. This is the only indent style to clearly associate the controlling statement and the beginning and the end of the block by aligning them vertically, which probably explains its widespread adoption.

 if (cond)
 {
	<body>
 }

"K&R style" is named after Kernighan & Ritchie because the examples in K&R are formatted this way. It is also called "kernel style" because the Unix kernel was written in it, or "One True Brace Style" (1TBS) by its partisans, or Egyptian brackets. The basic indent shown here is eight spaces (or one tab) per level; four spaces are much less common. This style was popular when programmers worked on small displays (or paper!) becuase it saves vertical space but the opening brace is easy to miss at the end of a long condition in an "if" or "while" statement.

 if (cond) {
	<body>
 }

"Whitesmiths style" - popularised 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 (cond)
	{
	<body>
	}

"GNU style" - Used throughout GNU Emacs and the 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 (cond)
  {
    <body>
  }

Many related languages such as Perl offer the same choices while others, following B, eschew braces and rely entirely on relative indentation to express block structure. In Python, braces can be used to override indentation.

[Jargon File]

Last updated: 2013-05-14

Nearby terms:

indentationindent styleIndependent Computing Architecture

Try this search on Wikipedia, OneLook, Google


Loading