In
computer programming, indentation describes formatting
source code with
whitespace to the left of code text often to visually show that a sequence of code lines is syntactically a
code block. Typically, the lines of a block are aligned with an amount of white space that indicates the block's depth in the
hierarchical structure of the code. Each inner level of the hierarchy is indented by a multiple of this
indentation width. White space in code is typically stored as
whitespace characters. For a
free-form language, indentation is exclusively for the
programmer since a code processor (i.e.
compiler,
interpreter) ignores whitespace characters. Code can have inconsistent or even no indentation, but in general is formatted with somewhat consistent indentation. Some languages rely on indentation to demarcate block structure, often via the
off-side rule. Due to this
syntax requirement, the code must have a level of consistency that is not required in free-form language code. The
neologisms
outdent,
unindent and
dedent describe the opposite of indentation aligning code text of a line to the left of the previous line.
Variations Common variations in the implementation of indentation include: how much to indent a block at each level of the code hierarchy, usually measured in spaces, and whether to store
whitespace characters as
space or
tab characters. Although there are common practices, consensus is not universal. These variations are driven by factors that may include but are not limited to: language syntax,
organizational mandate and personal preference.
Common practices The following table identifies notable practices with respect to code indentation.
Elastic tabstops In 2006, a new method of indentation was proposed, called
elastic tabstops. ==References==