Indentation style
本文只记录“是什么”,不讨论“好”“坏”。
In computer programming, indentation style is a convention, a.k.a. style, governing the indentation of blocks of source code that is generally intended to convey structure.
Generally, an indentation style uses the same width of whitespace (indentation size) before each line of a group of code so that they appear to be related.
As whitespace consists of both space
and tab
characters, a programmer can choose which to use - often entering them via the space key or tab key on the keyboard.
K&R
The position of braces is less important, although people hold passionate beliefs. We have chosen one of several popular styles. Pick a style that suits you, then use it consistently.
1 | while (x == y) { |
1 | int main(int argc, char *argv[]) |
One True Brace / 1TBS / OTBS
1 | bool is_negative(x) { |
Linux kernel
1 | int power(int x, int y) |
Stroustrup
1 | if (x < 0) { |
1 | class Vector { |
Allman
1 | while (x == y) |
GNU
1 | while (x == y) |
Whitesmiths
1 | while (x == y) |
Ratliff
1 | while (x == y) { |
Horstmann
1 | while (x == y) |
Pico
1 | while (x == y) |
Lisp
1 | while (x == y) |
APL
1 |
|
Python
1 | while x == y: |