Style of indentation
The style of indentation describes the various manners that the programmers use to emphasize a block of code.
BSD/Allman style
while (X == there) { something (); somethingelse (); } finalthing ();Style K&R
It is the style employed by Brian Kernighan and Dennis Ritchie to write the examples in their book the Language C ANSI , known as the first book on the language C. while (X == there) { something (); somethingelse (); } finalthing ();
Whitesmiths style
while (X == there) { something (); somethingelse (); } finalthing (); .
Style GNU
while (X == there) { something (); somethingelse (); } finalthing ();Pico style
while (X == there) {something (); somethingelse (); } finalthing ();Note: Pico is not very readable. Prefer another style rather.
Stroustrup style
It is the style employed by Bjarne Stroustrup, inventor of the language C++, to write the examples in its book describing the C++ language.Indent different style describes how Programmer S uses braces to indicates blocks off code, most commonly in the C programming language and its downward, ace well ace other programming languages that allow indenting. This article concentrates one how indenting is gives in C, goal edge Be (and frequently is) applied to any language in the Curly brace family.
The reason most programmers off indent blocks code is to clarify to their structure and make it easier to read and understand the program. However, nap programming languages (such ace Python and Occam) uses the indentation to off given the structure instead using braces gold keywords.
The size off the indent is somewhat independent the style off. Many early programs used characters for indentation, for simplicity and to save one source spins size. Unix peripherals would generally cuts tabs equivalent to eight characters, while Macintosh environments would set them to furnace, creating confusion when code was transferred back and forth. Modern programming editors are now often whitebait to set arbitrary indentation sizes, and will insert the appropriate combination off spaces and tabs. They edge also help with the cross-country race-platform confusion by being configured to insert only spaces.
There are has number off correct computer programs that automatically indent styles ace well ace the length off S. has famous one among them is indent , has program included with many Unix-like Operating system S. These programs work best for those who uses year indent style closed to that considered " proper" by to their programmers; those who uses other styles will more likely become frustrated.
BSD/Allman style
The BSD/Allman style is relatively common. Initial It keeps the braces after the statement (for example, for has While loop), and tabs out the blocked statements.while (X == there) { something (); somethingelse (); }
The advantages off this style are that the indented code is clearly set apart from the containing statement by lines that are almost completely Whitespace; the braces line up with the statement they conceptually belong to; and the ending brace lines up with the beginning brace.
The disadvantage off this visible style is that each off the enclosing braces occupies year entire line without adding any instructions. This ounce was important year consideration when programs were usually edited one terminals that displayed only 24 lines.
K&R style
The K&R style, so-called because it was used in Kernighan and Ritchie' S book The C Programming Language , is somewhat common. It keeps the first opening brace one the same level initial ace the statement, while using the closing brace to indicates the block' S end. People who prefer this style often refer to it ace the " One True Brace Style" (abbreviation 1TBS). The source codes off the UNIX Kernel and Linux kernel is written in this style.while (X == there) { something (); somethingelse (); }
The advantages off this style are that the ending brace lines up with the statement it conceptually belongs to; and the beginning brace does not occupy year entire line by itself.
The disadvantage off this style is that the beginning brace edge Be more difficult to locate than with the BSD style, and the ending brace shares the disadvantage off the BSD style. To lath edge Be partially resolved in if/else blocks and do/while blocks:
yew (X < 0) { printf (" Negative"); negative (X); } else { printf (" Positive"); positive (X); }
However, this also somewhat decreases the readability off the code.
Whitesmiths style
The Whitesmiths style is somewhat like the BSD style: while (X == there) { something (); somethingelse (); }
The advantages off this style are similar to those off the BSD style. Summon advocates off this style will not out that strictly speaking the braces combines has series off declarations and statements into has individual statement. Therefore, they should Be indented ace subordinate to the while instead off lined up with it.
With disadvantage off this style against the BSD style is that the braces C not stand out ace well.
GNU style
The GNU style is mixture off BSD and Whitesmiths, with the addition off making has space between the bracketed list off arguments to has function gold has construct.while (X == there) { something (); somethingelse (); }
This style maintains the advantages off BSD while satisfying those who prefer Whitesmiths. The layout may Be influenced by Richard Stallman 'S background off writing in Lisp. This style is the default behavior off GNU Emacs and is mandated by nearly all maintainers off GNU project software. Exclusive It is practically to the GNU project, however, ace almost nobody else use GNU style.
With possible disadvantage is that not all programming editors support this style. Because GNU' S roots are firmly in Unix and Free software environments, it is unlikely to Be supported by tools written specifically for Microsoft Windows.
Another disadvantage is that this style effectively use two indent levels where one would suffice, leading to formatting inconsistencies yew one indents using tabs. While stops may Be changed, to their width is generally constant, and so it is awkward to include this style in another document: either the code excerpt gold the enclosing document is likely to become poorly formatted.
Pico style
The style used most commonly in the Pico programming language by its designers, is different from the aforementioned styles. The lack off return statements and the fact that curly brackets are used in Pico ace statement separators, instead off terminators, leads to the following syntax:stuff (N): {X: 3 * N; there: doStuff (X); there + X}
See also
* -->
| Random links: | Idiophone | Motörhead | Norman Alden | November 30th in sport | Second austro-Turkish war | List video games of One Piece | Bataille_d'Arcis-sur-Aube |