Battle of the bracket
2005-3-19
The great big brackets have lasted for many years, and the developers are still quarreling in the position where the brackets should be placed in the code. In multiplayer project group, everyone gave others' code of code is a very bad thing, and a large number of unwanted formats in the version record will flood an important meaningful modification, and the code is tied between various formats. The position of the brackets as the most religious dispute, divided into the following factions.
K & R style:
IF () {
Name the name of the legendary Kernighan & Ritchie, is widely accepted by their sample code. This style is also known as the UnitX kernel, so it is also known as the Kernel Style, which is also called One true brace style by it. Also because C code mainly uses this style, it is also called a C style by other class C language users.
This style of popularization, one is because most of the teaching books use this style to save paper costs, and the second is widely accepted with Java's popularity. The advantage is that the code is quite compact, which is very valuable to low resolution display and print documents; the disadvantage is that it matches the brackets in some cases, and therefore produces a lot of sub-factions. Such as:
IF () {} else {}
versus
IF () {} else {}
When the conditions of the IF statement are long, there is also different ways:
IF (AverylongBooleaneXpression && ANOTHERVERYLONGBOOLEANEXPRESSION && YetanotherverryLongBooleaneXpression) {DOSMETHING ();
or
IF (AverylongBooleaneXpression && ANOTHERVERYLONGBOOLEANEXPRESSION && YetanotherverryLongBooleaneXpression) {DOSMETHING ();
Or simply put the brackets down
IF (AverylongBooleaneXpression && ANOTHERVERYLONGBOOLEANEXPRESSION && YetanotherverryLongBooleaneXpression) {DOSMETHING ();
In addition, many people like to use the crude arcs in the category and functions, and the standard K & R style is used in the statement. This style is used in the sample and the Apache project in the C # language standard. This kind of writing is also considered to be different from K & R.
Void dosomething () {if () {
ALLMAN style:
IF () {
Name the name of Berkeley hacker Eric Allman, also known as BSD style, also called ANSI style. The brackets are exclusive. This is the only style in the Java community in addition to K & R, in addition to K & R. Most of the DOS / Windows programmers use this style, also known as standard style in this community. The advantage is that all local brackets are symmetrical, most people agree that this type of code is more readily read; the disadvantage is a waste of space, such as:
Try {DOSMETHING ();} catch {dosomething ();
If you can't stand the waste, the best way is to use these rows to write comments.
GNU style:
IF () {DOSMETHING ();
All GNU Emacs and Free Software Foundation use this style, there is no other place in addition to this. The brackets are two sides.
Whitesmiths style:
IF () {DOSMETHING ();
Because WHITESMITHS C is famous, there are very few people now use this style. in conclusion
For this controversy that does not have the correct answer, the most effective way is to find any reason, do not have the relatively favorable. If the tool or package used in the project group is using a certain style, then it is consistent with it; in addition to this, choose the AlLman style that is most likely to manage.