|
Other Styles
In computer programming, an indent style is a convention governing the indentation of blocks of code to convey the program's structure. more...
Home
Bath & Body
Dietary Supplements,...
Hair Care
Hair Removal
Health Care
Makeup
Massage
Medical, Special Needs
Nail
Natural Therapies
Oral Care
Skin Care
Vision Care
Contact Lens Accessories
Eyeglass Cases
Eyeglass Frames
Flexible
Other Styles
Rimless
Vintage, Retro
Magnifying Glasses, Lenses
Other
Reading Glasses
Sunglasses
This article largely addresses the C programming language and its descendants, but can be (and frequently is) applied to most other programming languages (especially those in the curly bracket family). Indent style is just one aspect of programming style.
Indentation is not a requirement of most programming languages. Rather, programmers indent to better convey the structure of their program to human readers. In particular, indentation is used to show the relationship between control flow constructs such as conditions or loops and code contained within and outside them. However, some programming languages (such as Python and Occam) use the indentation to determine the structure instead of using braces or keywords.
The size of the indent is usually independent of the style. Many early programs used tab characters for indentation, for simplicity and to save on source file size. Unix editors generally view tabs as equivalent to eight characters, while Macintosh environments would set them to four, creating confusion when code was transferred back and forth. Modern programming editors are now often able to set arbitrary indentation sizes, and will insert the appropriate combination of spaces and tabs. They can also help with the cross-platform tab confusion by being configured to insert only spaces.
There are a number of computer programs that automatically correct indent styles as well as the length of tabs. A famous one among them is indent, a program included with many Unix-like operating systems. These programs work best for those who use an indent style close to that considered \"proper\" by their programmers; those who use other styles will more likely become frustrated.
K&R style
The K&R style, so-called because it was used in Kernighan and Ritchie's book The C Programming Language, is commonly used in C. It is less common for Objective C, C++, C#, and others. It keeps the first opening brace on the same line as control statement, indents the statements within the braces, and puts the closing brace on the same indentation level as the control statement (on a line of its own). Functions, however, are braced distinctly from statements; an opening function brace is placed on the line following the declaration, at the same indentation level as the declaration. This is because in the original C language argument types needed to be declared on the subsequent line, whereas, when no arguments were necessary, the opening brace would appear in the same line with the function declaration.
Advocates of this style sometimes refer to it as \"The One True Brace Style\" (abbreviated as 1TBS or OTBS) because of the precedent set by C (although advocates of other styles have been known to use similarly strong language). The source code of the Unix kernel and Linux kernel is written in this style, except that Linux indents are all tab characters with the default width of eight.
Read more at Wikipedia.org
|
|