Indentation (typesetting)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Chmarkine (talk | contribs) at 16:38, 17 August 2014 (→‎Indentation in programming: change to https if the server sends HSTS header, replaced: http://www.python.org → https://www.python.org using AWB). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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.

For example, this is an indentation of one non-breaking space:

 Indented block because this is something

and this is an indentation of two non-breaking spaces:

  Indented block 2

Pilcrow
Pilcrow

Outdentation is a neologism used in computer circles to describe placing text back to the left again.

Some languages (e.g., Hebrew and Arabic) are written right-to-left, and if indentation is used, in the above "left" and "right" should be swapped when referring to such languages.

Indentation in typesetting

There are two main types of first-line indent: normal and hanging. A "normal" indent indents the first line, as shown here, an indent of one centimeter:

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.

The other kind, a hanging indent, indents the rest of the text while leaving the first line in place; as shown here with a hanging indent of one centimeter:

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] Different indentation styles are commonly used. In 2006 a third method of indentation was proposed, called elastic tabstops.

Language Indent Note
Bash Varies Google uses 2 spaces.[2]
C# 4 As per Microsoft's C# Coding Conventions
CSS Varies Google, GitHub and Drupal uses 2 spaces.[3][4][5]
Go Tabs As per http://golang.org/doc/effective_go.html
Haskell ? Google uses 2 spaces.[6]
HTML Varies Google uses 2 spaces.[3] HTML Tidy defaults to 2 spaces.[7]
Java 4 Oracle says four spaces.[8] Android uses four spaces.[9]
JavaScript Varies Douglas Crockford advocates four spaces.[10] Google and GitHub uses two spaces.[11][12] jQuery uses tabs.[13] Firefox built-in jsbeautifier defaults to two spaces. The built-in prettyprinter in Chrome and Internet Explorer uses four spaces.
Lua 2 http://lua-users.org/wiki/LuaStyleGuide
Perl 4 As per Perl style guide
PHP Varies Drupal use 2 spaces.[14] PEAR and Zend uses 4 spaces.[15][16] CodeIgniter and WordPress uses tabs.[17][18] PSR-2 specifies 4 spaces.[19]
Python 4 As per PEP-8
Ruby 2 https://github.com/bbatsov/ruby-style-guide#source-code-layout
Rust 4 https://github.com/rust-lang/rust/wiki/Note-style-guide
Scala 2 As per Scala style guide
Tcl 4 As per Tcl style guide
Visual Basic 4 As per Microsoft's Visual Basic Coding Conventions

References

  1. ^ "Tabs versus Spaces: An Eternal Holy War". Jwz.org. 2007-01-05. Retrieved 2014-01-18.
  2. ^ https://google-styleguide.googlecode.com/svn/trunk/shell.xml
  3. ^ a b "Indentation : Indent by 2 spaces at a time". Google-styleguide.googlecode.com. Retrieved 2014-02-18.
  4. ^ "CSS formatting guidelines". Drupal.org. Retrieved 2014-01-18.
  5. ^ "CSS · Styleguide · GitHub". Github.com. Retrieved 2014-01-18.
  6. ^ "HaskellStyleGuide - ganeti - Style Guide for the Haskell code - Cluster-based virtualization management software - Google Project Hosting". Code.google.com. 2014-01-08. Retrieved 2014-01-18.
  7. ^ "HTML Tidy Configuration Options Quick Reference". Tidy.sourceforge.net. 2008-06-18. Retrieved 2014-01-18.
  8. ^ "Code Conventions for the Java Programming Language: 4. Indentation". Oracle.com. Retrieved 2014-01-18.
  9. ^ "Code Style Guidelines for Contributors | Android Developers". Source.android.com. Retrieved 2014-01-18.
  10. ^ "Code Conventions for the JavaScript Programming Language". Javascript.crockford.com. 2006-11-13. Retrieved 2014-01-18.
  11. ^ "JaveScript Style Rules". Google-styleguide.googlecode.com. Retrieved 2014-02-18.
  12. ^ "JavaScript 路 Styleguide 路 GitHub". Github.com. Retrieved 2014-01-18.
  13. ^ jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery". Contribute.jquery.org. Retrieved 2014-01-18.
  14. ^ "Coding standards". Drupal.org. Retrieved 2014-01-18.
  15. ^ "Manual :: Indenting and Line Length". Pear.php.net. Retrieved 2014-01-18.
  16. ^ "PHP Coding Standard (draft) - Contributors - Zend Framework Wiki". Framework.zend.com. Retrieved 2014-01-18.
  17. ^ "Style Guide : CodeIgniter User Guide". Ellislab.com. Retrieved 2014-01-18.
  18. ^ "WordPress › PHP Coding Standards « Make WordPress Core". Make.wordpress.org. Retrieved 2014-01-18.
  19. ^ "PHP : Coding Style Guide". Php-fig.org. Retrieved 2014-02-18.