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.

Indentation in typesetting

There are three main types of indentation, illustrated below in relation to borders representing the page dimensions.

A first-line indentation indents only the first line of each paragraph.
A first-line indentation of 2 em:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. 
A hanging indentation indents the remaining lines of each paragraph while leaving the first line of each paragraph in place.
A hanging indentation of 2 em:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
A block indentation indents the entire block of text.
A block indentation of 2 em on the left:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Indentation from both sides is commonly used for block quotations, here shown with 2 em on the left and right (which may amount to more on the right for certain lines, depending on word wrapping, if the text does not have justified alignment):
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
A justified-text example of a block quotation that has been block-indented from both sides by 3 em:
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

Indentation in programming

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.

LanguageIndentationNote
BashvariesFritz Mehner's Style Guide[2] suggests 2, 4, or 8 spaces and uses 2 in all examples. Google uses 2 spaces.[3]
CvariesThe Linux kernel uses 1 tab.[4][5] NASA uses 4 spaces.[6] Clinton Staley advocates 3 spaces.[7]
C++variesWebKit recommends 4 spaces.[8] Google uses 2 spaces.[9]
C#4 spacesPer Microsoft's C# Coding Conventions.[10]
CSSvariesDrupal, GitHub, and Google use 2 spaces.[11][12][13][14] WordPress uses tabs.[15]
Dartdart format uses 2 spaces.
Delphi2 spacesPer Delphi Style Guide.[16]
F#4 spacesAs per the F# style guide.[17]
Go1 tabPer "Effective Go".[18]
HaskellvariesGoogle uses 2 spaces.[19]
HTMLvariesGoogle uses 2 spaces.[13] HTML Tidy defaults to 2 spaces.[20]
JavavariesOracle uses 4 spaces.[21] Android uses 4 spaces.[22] Most Eclipse IDE components use tabs.
JavaScriptvariesDouglas 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]
Lua2 spacesPer Lua Style Guide.[29]
Perlvaries"perlstyle: Perl style guide" says Larry Wall prefers but does not mandate 4 spaces.[30]
PHPvariesDrupal 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]
PowerShellvaries4 spaces in The Unofficial PowerShell Best Practices and Style Guide.[37]
Python4 spacesPer PEP-8.[38] (1 tab is also sometimes used, but 4 spaces is preferred.)
Ruby2 spacesPer Ruby Style Guide.[39]
Rust4 spacesPer Rust Style Guide.[40]
Scala2 spacesPer Scala style guide.[41]
SwiftvariesGoogle uses 2 spaces.[42]
Tcl4 spacesPer Tcl style guide.[43]
Visual Basic4 spacesPer Microsoft's Visual Basic Coding Conventions.[44]
XMLvariesGoogle uses 2 spaces.[45]

References

  1. "Tabs versus Spaces: An Eternal Holy War". Jwz.org. 5 January 2007. Retrieved 18 January 2014.
  2. "Bash Style Guide and Coding Standard" (PDF). Lug.fh-swf.de.
  3. "Archived copy". Archived from the original on 26 June 2014. Retrieved 23 June 2014.{{cite web}}: CS1 maint: archived copy as title (link)
  4. "Archived copy". Archived from the original on 14 February 2015. Retrieved 15 February 2015.{{cite web}}: CS1 maint: archived copy as title (link)
  5. "Linux kernel coding style". Archived from the original on 11 June 2022. Retrieved 21 July 2022.
  6. "C STYLE GUIDE". NASA Technical Reports Server. August 1994.
  7. Staley, Clinton (2006). "C Program Style Rules". Cal Poly Department of Computer Science & Software Engineering.
  8. "Code Style Guidelines". WebKit. 7 November 2015. Retrieved 31 December 2021.
  9. Archived 2014-10-06 at the Wayback Machine
  10. Bill Wagner. "C# Coding Conventions (C# Programming Guide)". Msdn.microsoft.com. Retrieved 3 September 2017.
  11. "CSS formatting guidelines". Drupal.org. 14 January 2013. Retrieved 18 January 2014.
  12. "CSS · Styleguide · GitHub". Github.com. Retrieved 18 January 2014.
  13. 1 2 "Google HTML/CSS Style Guide". Google GitHub. Indentation. Archived from the original on 13 March 2016. Retrieved 13 March 2016. Indent by 2 spaces at a time. This is an HTML-rendered copy of the official version, which is maintained in XML format
  14. "styleguide: Style guides for Google-originated open-source projects". Github.com. 3 September 2017. Retrieved 3 September 2017.
  15. "WordPress › CSS Coding Standards « Make WordPress Core". Make.wordpress.org. 17 July 2012. Retrieved 20 July 2018.
  16. "Delphi's Object Pascal Style Guide - White Space Usage". Retrieved 13 December 2022.
  17. "F# code formatting guidelines". docs.microsoft.com. Retrieved 14 October 2020.
  18. "Effective Go – The Go Programming Language". golang.org. Retrieved 3 September 2017.
  19. "HaskellStyleGuide – ganeti – Style Guide for the Haskell code – Cluster-based virtualization management software – Google Project Hosting". Code.google.com. 8 January 2014. Archived from the original on 27 June 2013. Retrieved 18 January 2014.
  20. "HTML Tidy Configuration Options Quick Reference". Tidy.sourceforge.net. 18 June 2008. Retrieved 18 January 2014.
  21. "Code Conventions for the Java Programming Language: 4. Indentation". Oracle.com. Retrieved 18 January 2014.
  22. "Code Style Guidelines for Contributors | Android Developers". Source.android.com. Retrieved 18 January 2014.
  23. "Code Conventions for the JavaScript Programming Language". Javascript.crockford.com. 13 November 2006. Retrieved 18 January 2014.
  24. "JavaScript 路 Styleguide". Github.com. Archived from the original on 15 August 2013. Retrieved 18 January 2014.
  25. "JaveScript Style Rules". Google-styleguide.googlecode.com. Archived from the original on 16 February 2014. Retrieved 18 February 2014.
  26. jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery". Contribute.jquery.org. Retrieved 18 January 2014.
  27. "Style Guide · The Julia Language". docs.julialang.org.
  28. "Coding Conventions – Kotlin Programming Language". Kotlin.
  29. "lua-users wiki: Lua Style Guide". lua-users.org. Retrieved 3 September 2017.
  30. Allen, Jon (JJ) (ed.). "perlstyle: Perl style guide". Perl 5 Version 32.1 Documentation. Perl Foundation. Retrieved 19 April 2021.
  31. "Coding standards". Drupal.org. Retrieved 18 January 2014.
  32. "Manual :: Indenting and Line Length". Pear.php.net. Retrieved 18 January 2014.
  33. "PHP Coding Standard (draft) – Contributors – Zend Framework Wiki". Framework.zend.com. Archived from the original on 3 January 2008. Retrieved 18 January 2014.
  34. "Style Guide : CodeIgniter User Guide". Ellislab.com. Retrieved 18 January 2014.
  35. "WordPress › PHP Coding Standards « Make WordPress Core". Make.wordpress.org. 23 July 2012. Retrieved 18 January 2014.
  36. "PHP : Coding Style Guide". Php-fig.org. Archived from the original on 15 March 2014. Retrieved 18 February 2014.
  37. "Code Layout and Formatting – PowerShell Practice and Style". PowerShell Practice and Style. Retrieved 17 October 2021.
  38. "PEP 8 – Style Guide for Python Code". Python.org. Retrieved 3 September 2017.
  39. Batsov, Bozhidar (3 September 2017). "ruby-style-guide: A community-driven Ruby coding style guide". Github.com. Retrieved 3 September 2017.
  40. "rust: A safe, concurrent, practical language". Github.com. 3 September 2017. Retrieved 3 September 2017.
  41. "Indentation – Scala Documentation". docs.scala-lang.org. Retrieved 3 September 2017.
  42. "Swift Style Guide". google.github.io. Retrieved 17 October 2021.
  43. Ray Johnson. "Tcl Style Guide" (PDF). Tcl.tk. Retrieved 3 September 2017.
  44. "Structured Coding Conventions". msdn.microsoft.com. Retrieved 3 September 2017.
  45. "Google XML Document Format Style Guide". google.github.io. Google. Retrieved 17 October 2021.
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.