In the written form of many languages, an indentation or indent is an empty space at the beginning of a line to signal the start of a new paragraph. Many computer languages have adopted this technique to designate "paragraphs" or other logical blocks in the program.
For example, the following lines are indented, using between one and six spaces:
This paragraph is indented by 1 space.
This paragraph is indented by 3 spaces.
This paragraph is indented by 6 spaces.
In computer programming, the neologisms outdent, unindent and dedent are used to describe the reversal of the indentation process, realigning text with the page margin (or with previous, lesser, levels of indentation).
In right-to-left languages (e.g. Hebrew and Arabic), indentation is used just the same, but from the right margin of the paper, where the line begins.
There are three main types of indentation, illustrated below in relation to borders representing the page dimensions.
In computer programming languages, indentation is used to format program source code to improve readability. Indentation is generally only of use to programmers; compilers and interpreters rarely care how much whitespace is present in between programming statements. However, certain programming languages rely on the use of indentation to demarcate programming structure, often using a variation of the off-side rule. The Haskell, Occam, Python, MoonScript, and Ya programming languages rely on indentation in this way.
Opinions about where to indent, whether to use spaces or tabs, and how many spaces to use are often hotly debated among programmers, leading some to describe indentation disputes as akin to a religious war.[1] In 2006 a third method of indentation was proposed, called elastic tabstops.
In addition to general indentation of statements, different bracket indentation styles are commonly used.
This table may lend undue weight to a single company's coding practices. (March 2016) (Learn how and when to remove this template message) |
Language | Indentation | Note |
---|---|---|
Bash | varies | Fritz Mehner's Style Guide[2] suggests 2, 4, or 8 spaces and uses 2 in all examples. Google uses 2 spaces.[3] |
C | varies | The Linux kernel uses 1 tab.[4][5] NASA uses 4 spaces.[6] Clinton Staley advocates 3 spaces.[7] |
C++ | varies | WebKit recommends 4 spaces.[8] Google uses 2 spaces.[9] |
C# | 4 spaces | Per Microsoft's C# Coding Conventions.[10] |
CSS | varies | Drupal, GitHub, and Google use 2 spaces.[11][12][13][14] WordPress uses tabs.[15] |
Dart | dart format uses 2 spaces.
| |
Delphi | 2 spaces | Per Delphi Style Guide.[16] |
F# | 4 spaces | As per the F# style guide.[17] |
Go | 1 tab | Per "Effective Go".[18] |
Haskell | varies | Google uses 2 spaces.[19] |
HTML | varies | Google uses 2 spaces.[13] HTML Tidy defaults to 2 spaces.[20] |
Java | varies | Oracle uses 4 spaces.[21] Android uses 4 spaces.[22] Most Eclipse IDE components use tabs. |
JavaScript | varies | Douglas Crockford advocates 4 spaces.[23] GitHub and Google uses 2 spaces.[24][25] jQuery uses tabs.[26] Firefox's built-in jsbeautifier defaults to 2 spaces. The built-in prettyprinter in Google Chrome and Internet Explorer uses 4 spaces. |
Julia | 4 spaces | Per Julia style guide.[27] |
Kotlin | 4 spaces | Per Kotlin style guide.[28] |
Lua | 2 spaces | Per Lua Style Guide.[29] |
Perl | varies | "perlstyle: Perl style guide" says Larry Wall prefers but does not mandate 4 spaces.[30] |
PHP | varies | Drupal use 2 spaces.[31] PEAR and Zend use 4 spaces.[32][33] CodeIgniter and WordPress uses tabs.[34][35] PSR-2 specifies 4 spaces.[36] |
PowerShell | varies | 4 spaces in The Unofficial PowerShell Best Practices and Style Guide.[37] |
Python | 4 spaces | Per PEP-8.[38] (1 tab is also sometimes used, but 4 spaces is preferred.) |
Ruby | 2 spaces | Per Ruby Style Guide.[39] |
Rust | 4 spaces | Per Rust Style Guide.[40] |
Scala | 2 spaces | Per Scala style guide.[41] |
Swift | varies | Google uses 2 spaces.[42] |
Tcl | 4 spaces | Per Tcl style guide.[43] |
Visual Basic | 4 spaces | Per Microsoft's Visual Basic Coding Conventions.[44] |
XML | varies | Google uses 2 spaces.[45] |
Original source: https://en.wikipedia.org/wiki/Indentation (typesetting).
Read more |