Jump to content

Indentation (typesetting): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
Removed clean-up tag
Rescuing 4 sources and tagging 0 as dead. #IABot (v1.5)
Line 62: Line 62:
!Language !! Indent !! Note
!Language !! Indent !! Note
|-
|-
| [[Bash (Unix shell)|Bash]] || varies || Fritz Mehner's Style Guide<ref>{{cite web|url=https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf|format=PDF|title=Bash Style Guide and Coding Standard|website=Lug.fh-swf.de}}</ref> suggests 2, 4, or 8 spaces and uses 2 in all examples. [[Google]] uses 2 spaces.<ref>[https://google-styleguide.googlecode.com/svn/trunk/shell.xml] {{dead link|date=September 2017}}</ref>
| [[Bash (Unix shell)|Bash]] || varies || Fritz Mehner's Style Guide<ref>{{cite web|url=https://lug.fh-swf.de/vim/vim-bash/StyleGuideShell.en.pdf|format=PDF|title=Bash Style Guide and Coding Standard|website=Lug.fh-swf.de}}</ref> suggests 2, 4, or 8 spaces and uses 2 in all examples. [[Google]] uses 2 spaces.<ref>{{cite web |url=https://google-styleguide.googlecode.com/svn/trunk/shell.xml |title=Archived copy |accessdate=2014-06-23 |deadurl=yes |archiveurl=https://web.archive.org/web/20140626134128/http://google-styleguide.googlecode.com/svn/trunk/shell.xml |archivedate=2014-06-26 |df= }} </ref>
|-
|-
| [[C (programming language)|C]] || varies || The [[Linux kernel]] uses 8 spaces.<ref>[https://www.kernel.org/doc/Documentation/CodingStyle] {{dead link|date=September 2017}}</ref> [[NASA]] uses 4 spaces.<ref>{{cite web|url=http://homepages.inf.ed.ac.uk/dts/pm/Papers/nasa-c-style.pdf|format=PDF|title=C STYLE GUIDE|date=August 1994|website=Homepages.inf.ed.ac.uk|accessdate=3 September 2017}}</ref>
| [[C (programming language)|C]] || varies || The [[Linux kernel]] uses 8 spaces.<ref>{{cite web |url=https://www.kernel.org/doc/Documentation/CodingStyle |title=Archived copy |accessdate=2015-02-15 |deadurl=yes |archiveurl=https://web.archive.org/web/20150214004842/https://www.kernel.org/doc/Documentation/CodingStyle |archivedate=2015-02-14 |df= }} </ref> [[NASA]] uses 4 spaces.<ref>{{cite web|url=http://homepages.inf.ed.ac.uk/dts/pm/Papers/nasa-c-style.pdf|format=PDF|title=C STYLE GUIDE|date=August 1994|website=Homepages.inf.ed.ac.uk|accessdate=3 September 2017}}</ref>
|-
|-
| [[C++]] || varies || [[Google]] uses 2 spaces.<ref>[http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Spaces_vs._Tabs] {{dead link|date=September 2017}}</ref>
| [[C++]] || varies || [[Google]] uses 2 spaces.<ref>[http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Spaces_vs._Tabs] {{webarchive|url=https://web.archive.org/web/20141006093744/http://google-styleguide.googlecode.com/svn/trunk/cppguide.html |date=2014-10-06 }}</ref>
|-
|-
| [[C Sharp (programming language)|C#]] || 4&nbsp;spaces || As per [[Microsoft]]'s C# Coding Conventions.<ref>{{cite web|url=http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx|title=C# Coding Conventions (C# Programming Guide)|author=Bill Wagner|website=Msdn.microsoft.com|accessdate=3 September 2017}}</ref>
| [[C Sharp (programming language)|C#]] || 4&nbsp;spaces || As per [[Microsoft]]'s C# Coding Conventions.<ref>{{cite web|url=http://msdn.microsoft.com/en-us/library/vstudio/ff926074.aspx|title=C# Coding Conventions (C# Programming Guide)|author=Bill Wagner|website=Msdn.microsoft.com|accessdate=3 September 2017}}</ref>
Line 82: Line 82:
| [[Java (programming language)|Java]] || 4&nbsp;spaces || [[Oracle Corporation|Oracle]] uses 4 spaces.<ref>{{cite web|url=http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#262 |title=Code Conventions for the Java Programming Language: 4. Indentation |website=Oracle.com |date= |accessdate=2014-01-18}}</ref> [[Android (operating system)|Android]] uses 4 spaces.<ref>{{cite web|url=http://source.android.com/source/code-style.html#use-spaces-for-indentation |title=Code Style Guidelines for Contributors &#124; Android Developers |website=Source.android.com |date= |accessdate=2014-01-18}}</ref>
| [[Java (programming language)|Java]] || 4&nbsp;spaces || [[Oracle Corporation|Oracle]] uses 4 spaces.<ref>{{cite web|url=http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-136091.html#262 |title=Code Conventions for the Java Programming Language: 4. Indentation |website=Oracle.com |date= |accessdate=2014-01-18}}</ref> [[Android (operating system)|Android]] uses 4 spaces.<ref>{{cite web|url=http://source.android.com/source/code-style.html#use-spaces-for-indentation |title=Code Style Guidelines for Contributors &#124; Android Developers |website=Source.android.com |date= |accessdate=2014-01-18}}</ref>
|-
|-
| [[JavaScript]] || varies || [[Douglas Crockford]] advocates 4 spaces.<ref>{{cite web|url=http://javascript.crockford.com/code.html |title=Code Conventions for the JavaScript Programming Language |website=Javascript.crockford.com |date=2006-11-13 |accessdate=2014-01-18}}</ref> GitHub and Google uses 2 spaces.<ref>{{cite web|url=https://github.com/styleguide/javascript |title=JavaScript 路 Styleguide |website=Github.com|accessdate=2014-01-18}}</ref><ref>{{cite web|url=http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Code_formatting |title=JaveScript Style Rules |website=Google-styleguide.googlecode.com |accessdate=2014-02-18}}</ref> [[jQuery]] uses tabs.<ref>{{cite web|author=jQuery Foundation - jquery.org |url=http://contribute.jquery.org/style-guide/js/ |title=JavaScript Style Guide &#124; Contribute to jQuery |website=Contribute.jquery.org |date= |accessdate=2014-01-18}}</ref> [[Firefox]]'s built-in jsbeautifier defaults to 2 spaces. The built-in [[prettyprint]]er in [[Google Chrome]] and [[Internet Explorer]] uses 4 spaces.
| [[JavaScript]] || varies || [[Douglas Crockford]] advocates 4 spaces.<ref>{{cite web|url=http://javascript.crockford.com/code.html |title=Code Conventions for the JavaScript Programming Language |website=Javascript.crockford.com |date=2006-11-13 |accessdate=2014-01-18}}</ref> GitHub and Google uses 2 spaces.<ref>{{cite web |url=https://github.com/styleguide/javascript |title=JavaScript 路 Styleguide |website=Github.com |accessdate=2014-01-18 |deadurl=yes |archiveurl=https://web.archive.org/web/20130815075924/https://github.com/styleguide/javascript |archivedate=2013-08-15 |df= }}</ref><ref>{{cite web|url=http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml#Code_formatting |title=JaveScript Style Rules |website=Google-styleguide.googlecode.com |accessdate=2014-02-18}}</ref> [[jQuery]] uses tabs.<ref>{{cite web|author=jQuery Foundation - jquery.org |url=http://contribute.jquery.org/style-guide/js/ |title=JavaScript Style Guide &#124; Contribute to jQuery |website=Contribute.jquery.org |date= |accessdate=2014-01-18}}</ref> [[Firefox]]'s built-in jsbeautifier defaults to 2 spaces. The built-in [[prettyprint]]er in [[Google Chrome]] and [[Internet Explorer]] uses 4 spaces.
|-
|-
| [[Lua (programming language)|Lua]] || 2&nbsp;spaces || As per Lua Style Guide.<ref>{{cite web|url=http://lua-users.org/wiki/LuaStyleGuide|title=lua-users wiki: Lua Style Guide|website=lua-users.org|accessdate=3 September 2017}}</ref>
| [[Lua (programming language)|Lua]] || 2&nbsp;spaces || As per Lua Style Guide.<ref>{{cite web|url=http://lua-users.org/wiki/LuaStyleGuide|title=lua-users wiki: Lua Style Guide|website=lua-users.org|accessdate=3 September 2017}}</ref>

Revision as of 03:10, 5 September 2017

In the written form of many languages, an indentation 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 and unindent 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 the first line.
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 rest of the text while leaving the first line 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, and Ya programming languages rely on indentation in this way.

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 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.

Language Indent 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 8 spaces.[4] NASA uses 4 spaces.[5]
C++ varies Google uses 2 spaces.[6]
C# 4 spaces As per Microsoft's C# Coding Conventions.[7]
CSS varies Drupal, GitHub, and Google use 2 spaces.[8][9][10][11]
Delphi 2 spaces Default in RAD Studio.[citation needed]
Go 1 tab As per "Effective Go".[12]
Haskell varies Google uses 2 spaces.[13]
HTML varies Google uses 2 spaces.[10] HTML Tidy defaults to 2 spaces.[14]
Java 4 spaces Oracle uses 4 spaces.[15] Android uses 4 spaces.[16]
JavaScript varies Douglas Crockford advocates 4 spaces.[17] GitHub and Google uses 2 spaces.[18][19] jQuery uses tabs.[20] Firefox's built-in jsbeautifier defaults to 2 spaces. The built-in prettyprinter in Google Chrome and Internet Explorer uses 4 spaces.
Lua 2 spaces As per Lua Style Guide.[21]
Perl 4 spaces As per "perlstyle: Perl style guide".[22]
PHP varies Drupal use 2 spaces.[23] PEAR and Zend use 4 spaces.[24][25] CodeIgniter and WordPress uses tabs.[26][27] PSR-2 specifies 4 spaces.[28]
Python 4 spaces As per PEP-8.[29]
Ruby 2 spaces As per Ruby Style Guide.[30]
Rust 4 spaces As per Rust Style Guide.[31]
Scala 2 spaces As per Scala style guide.[32]
Tcl 4 spaces As per Tcl style guide.[33]
Visual Basic 4 spaces As per Microsoft's Visual Basic Coding Conventions.[34]

References

  1. ^ "Tabs versus Spaces: An Eternal Holy War". Jwz.org. 2007-01-05. Retrieved 2014-01-18.
  2. ^ "Bash Style Guide and Coding Standard" (PDF). Lug.fh-swf.de.
  3. ^ "Archived copy". Archived from the original on 2014-06-26. Retrieved 2014-06-23. {{cite web}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)CS1 maint: archived copy as title (link)
  4. ^ "Archived copy". Archived from the original on 2015-02-14. Retrieved 2015-02-15. {{cite web}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)CS1 maint: archived copy as title (link)
  5. ^ "C STYLE GUIDE" (PDF). Homepages.inf.ed.ac.uk. August 1994. Retrieved 3 September 2017.
  6. ^ [1] Archived 2014-10-06 at the Wayback Machine
  7. ^ Bill Wagner. "C# Coding Conventions (C# Programming Guide)". Msdn.microsoft.com. Retrieved 3 September 2017.
  8. ^ "CSS formatting guidelines". Drupal.org. Retrieved 2014-01-18.
  9. ^ "CSS · Styleguide · GitHub". Github.com. Retrieved 2014-01-18.
  10. ^ a b "Google HTML/CSS Style Guide". Google GitHub. Google. Indentation. Retrieved 2016-03-13. Indent by 2 spaces at a time. This is an HTML-rendered copy of the official version, which is maintained in XML format
  11. ^ "styleguide: Style guides for Google-originated open-source projects". Github.com. 3 September 2017. Retrieved 3 September 2017.
  12. ^ "Effective Go - The Go Programming Language". golang.org. Retrieved 3 September 2017.
  13. ^ "HaskellStyleGuide - ganeti - Style Guide for the Haskell code - Cluster-based virtualization management software - Google Project Hosting". Code.google.com. 2014-01-08. Archived from the original on June 27, 2013. Retrieved 2014-01-18. {{cite web}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)
  14. ^ "HTML Tidy Configuration Options Quick Reference". Tidy.sourceforge.net. 2008-06-18. Retrieved 2014-01-18.
  15. ^ "Code Conventions for the Java Programming Language: 4. Indentation". Oracle.com. Retrieved 2014-01-18.
  16. ^ "Code Style Guidelines for Contributors | Android Developers". Source.android.com. Retrieved 2014-01-18.
  17. ^ "Code Conventions for the JavaScript Programming Language". Javascript.crockford.com. 2006-11-13. Retrieved 2014-01-18.
  18. ^ "JavaScript 路 Styleguide". Github.com. Archived from the original on 2013-08-15. Retrieved 2014-01-18. {{cite web}}: Unknown parameter |deadurl= ignored (|url-status= suggested) (help)
  19. ^ "JaveScript Style Rules". Google-styleguide.googlecode.com. Retrieved 2014-02-18.
  20. ^ jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery". Contribute.jquery.org. Retrieved 2014-01-18.
  21. ^ "lua-users wiki: Lua Style Guide". lua-users.org. Retrieved 3 September 2017.
  22. ^ Allen, Jon (JJ), ed. (2015-06-15). "perlstyle: Perl style guide". Perl 5 Version 22.0 Documentation. Perl Foundation. Retrieved 2016-03-13.
  23. ^ "Coding standards". Drupal.org. Retrieved 2014-01-18.
  24. ^ "Manual :: Indenting and Line Length". Pear.php.net. Retrieved 2014-01-18.
  25. ^ "PHP Coding Standard (draft) - Contributors - Zend Framework Wiki". Framework.zend.com. Retrieved 2014-01-18.
  26. ^ "Style Guide : CodeIgniter User Guide". Ellislab.com. Retrieved 2014-01-18.
  27. ^ "WordPress › PHP Coding Standards « Make WordPress Core". Make.wordpress.org. Retrieved 2014-01-18.
  28. ^ "PHP : Coding Style Guide". Php-fig.org. Retrieved 2014-02-18.
  29. ^ "PEP 8 -- Style Guide for Python Code". Python.org. Retrieved 3 September 2017.
  30. ^ Batsov, Bozhidar (3 September 2017). "ruby-style-guide: A community-driven Ruby coding style guide". Github.com. Retrieved 3 September 2017.
  31. ^ "rust: A safe, concurrent, practical language". Github.com. 3 September 2017. Retrieved 3 September 2017.
  32. ^ "Indentation - Scala Documentation". docs.scala-lang.org. Retrieved 3 September 2017.
  33. ^ Ray Johnson. "Tcl Style Guide" (PDF). Tcl.tk. Retrieved 3 September 2017.
  34. ^ "Structured Coding Conventions". msdn.microsoft.com. Retrieved 3 September 2017.