Indentation (typesetting)
Look up indentation in Wiktionary, the free dictionary. |
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 2 spaces.
This paragraph is indented by 4 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.
In right-to-left languages (e.g., Hebrew and Arabic), identation is used just the same, but from the right margin of the paper, where the line begins.
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:
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:
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 | Varies | The Linux kernel uses 8 spaces.[3] NASA uses 4 spaces.[4] |
C++ | Varies | Google uses 2 spaces.[5] |
C# | 4 | As per Microsoft's C# Coding Conventions |
CSS | Varies | Google, GitHub and Drupal uses 2 spaces.[6][7][8] |
Go | Tabs | As per http://golang.org/doc/effective_go.html |
Haskell | ? | Google uses 2 spaces.[9] |
HTML | Varies | Google uses 2 spaces.[6] HTML Tidy defaults to 2 spaces.[10] |
Java | 4 | Oracle says four spaces.[11] Android uses four spaces.[12] |
JavaScript | Varies | Douglas Crockford advocates four spaces.[13] Google and GitHub uses two spaces.[14][15] jQuery uses tabs.[16] Firefox's built-in jsbeautifier defaults to two spaces. The built-in prettyprinter in Google 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.[17] PEAR and Zend uses 4 spaces.[18][19] CodeIgniter and WordPress uses tabs.[20][21] PSR-2 specifies 4 spaces.[22] |
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
- ↑ "Tabs versus Spaces: An Eternal Holy War". Jwz.org. 2007-01-05. Retrieved 2014-01-18.
- ↑ https://google-styleguide.googlecode.com/svn/trunk/shell.xml
- ↑ https://www.kernel.org/doc/Documentation/CodingStyle
- ↑ http://homepages.inf.ed.ac.uk/dts/pm/Papers/nasa-c-style.pdf
- ↑ http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Spaces_vs._Tabs
- 1 2 "Indentation : Indent by 2 spaces at a time". Google-styleguide.googlecode.com. Retrieved 2014-02-18.
- ↑ "CSS formatting guidelines". Drupal.org. Retrieved 2014-01-18.
- ↑ "CSS · Styleguide · GitHub". Github.com. Retrieved 2014-01-18.
- ↑ "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.
- ↑ "HTML Tidy Configuration Options Quick Reference". Tidy.sourceforge.net. 2008-06-18. Retrieved 2014-01-18.
- ↑ "Code Conventions for the Java Programming Language: 4. Indentation". Oracle.com. Retrieved 2014-01-18.
- ↑ "Code Style Guidelines for Contributors | Android Developers". Source.android.com. Retrieved 2014-01-18.
- ↑ "Code Conventions for the JavaScript Programming Language". Javascript.crockford.com. 2006-11-13. Retrieved 2014-01-18.
- ↑ "JaveScript Style Rules". Google-styleguide.googlecode.com. Retrieved 2014-02-18.
- ↑ "JavaScript 路 Styleguide 路 GitHub". Github.com. Retrieved 2014-01-18.
- ↑ jQuery Foundation - jquery.org. "JavaScript Style Guide | Contribute to jQuery". Contribute.jquery.org. Retrieved 2014-01-18.
- ↑ "Coding standards". Drupal.org. Retrieved 2014-01-18.
- ↑ "Manual :: Indenting and Line Length". Pear.php.net. Retrieved 2014-01-18.
- ↑ "PHP Coding Standard (draft) - Contributors - Zend Framework Wiki". Framework.zend.com. Retrieved 2014-01-18.
- ↑ "Style Guide : CodeIgniter User Guide". Ellislab.com. Retrieved 2014-01-18.
- ↑ "WordPress › PHP Coding Standards « Make WordPress Core". Make.wordpress.org. Retrieved 2014-01-18.
- ↑ "PHP : Coding Style Guide". Php-fig.org. Retrieved 2014-02-18.
Wikimedia Commons has media related to Indentation (typesetting). |