aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2000-08-22 00:20:21 +0000
committerMark Whitley <markw@lineo.com>2000-08-22 00:20:21 +0000
commit2368a387edced9e9722d6b8e7a82bd2e191ca347 (patch)
tree6123b4d69633c0953caba7cfe791b3d8f16ec9ba
parente4c4d69c0488f554bc2dbb8cd1ea7deff0da3214 (diff)
downloadbusybox-w32-2368a387edced9e9722d6b8e7a82bd2e191ca347.tar.gz
busybox-w32-2368a387edced9e9722d6b8e7a82bd2e191ca347.tar.bz2
busybox-w32-2368a387edced9e9722d6b8e7a82bd2e191ca347.zip
Some additional tips and formatting changes.
-rw-r--r--docs/style-guide.txt84
1 files changed, 56 insertions, 28 deletions
diff --git a/docs/style-guide.txt b/docs/style-guide.txt
index d1257b755..72d3b9375 100644
--- a/docs/style-guide.txt
+++ b/docs/style-guide.txt
@@ -15,6 +15,7 @@ files by typing 'indent myfile.c myfile.h' and it will magically apply all the
15right formatting rules to your file. Please _do_not_ run this on all the files 15right formatting rules to your file. Please _do_not_ run this on all the files
16in the directory, just your own. 16in the directory, just your own.
17 17
18
18Declaration Order 19Declaration Order
19----------------- 20-----------------
20 21
@@ -28,15 +29,22 @@ Here is the order in which code should be laid out in a file:
28 - function declarations (if necessary) 29 - function declarations (if necessary)
29 - function implementations 30 - function implementations
30 31
32
31Whitespace 33Whitespace
32---------- 34----------
33 35
34Tabs vs Spaces in Line Indentation: The preference in Busybox is to indent 36This is everybody's favorite flame topic so let's get it out of the way right
35lines with tabs. Do not indent lines with spaces and do not indents lines 37up front.
36using a mixture of tabs and spaces. (The indentation style in the Apache and 38
37Postfix source does this sort of thing: \s\s\s\sif (expr) {\n\tstmt; --ick.) 39
38The only exception to this rule is multi-line comments that use an asterisk at 40Tabs vs Spaces in Line Indentation
39the beginning of each line, i.e.: 41~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42
43The preference in Busybox is to indent lines with tabs. Do not indent lines
44with spaces and do not indents lines using a mixture of tabs and spaces. (The
45indentation style in the Apache and Postfix source does this sort of thing:
46\s\s\s\sif (expr) {\n\tstmt; --ick.) The only exception to this rule is
47multi-line comments that use an asterisk at the beginning of each line, i.e.:
40 48
41 /t/* 49 /t/*
42 /t * This is a block comment. 50 /t * This is a block comment.
@@ -52,7 +60,10 @@ lines is that you can set your editor to display tabs at *watever* number of
52spaces is desired and the code will still look fine. 60spaces is desired and the code will still look fine.
53 61
54 62
55Operator Spacing: Put spaces between terms and operators. Example: 63Operator Spacing
64~~~~~~~~~~~~~~~~
65
66Put spaces between terms and operators. Example:
56 67
57 Don't do this: 68 Don't do this:
58 69
@@ -74,7 +85,10 @@ Operator Spacing: Put spaces between terms and operators. Example:
74 if ((argc-1) - (optind+1) > 0) 85 if ((argc-1) - (optind+1) > 0)
75 86
76 87
77Bracket Spacing: If an opening bracket starts a function, it should be on the 88Bracket Spacing
89~~~~~~~~~~~~~~~
90
91If an opening bracket starts a function, it should be on the
78next line with no spacing before it. However, if a bracet follows an opening 92next line with no spacing before it. However, if a bracet follows an opening
79control block, it should be on the same line with a single space (not a tab) 93control block, it should be on the same line with a single space (not a tab)
80between it and the opening control block statment. Examples: 94between it and the opening control block statment. Examples:
@@ -89,28 +103,11 @@ between it and the opening control block statment. Examples:
89 while (!done) { 103 while (!done) {
90 do { 104 do {
91 105
92Also, please "cuddle" your else statments by putting the else keyword on the
93same line after the right bracket that closes an 'if' statment.
94
95 Don't do this:
96
97 if (foo) {
98 stmt;
99 }
100 else {
101 stmt;
102 }
103
104 Do this instead:
105
106 if (foo) {
107 stmt;
108 } else {
109 stmt;
110 }
111 106
107Paren Spacing
108~~~~~~~~~~~~~
112 109
113Paren Spacing: Put a space between C keywords and left parens, but not between 110Put a space between C keywords and left parens, but not between
114function names and the left paren that starts it's parameter list (whether it 111function names and the left paren that starts it's parameter list (whether it
115is being declared or called). Examples: 112is being declared or called). Examples:
116 113
@@ -130,6 +127,31 @@ is being declared or called). Examples:
130 ... 127 ...
131 baz = my_func(1, 2); 128 baz = my_func(1, 2);
132 129
130
131Cuddled Elses
132~~~~~~~~~~~~~
133
134Also, please "cuddle" your else statments by putting the else keyword on the
135same line after the right bracket that closes an 'if' statment.
136
137 Don't do this:
138
139 if (foo) {
140 stmt;
141 }
142 else {
143 stmt;
144 }
145
146 Do this instead:
147
148 if (foo) {
149 stmt;
150 } else {
151 stmt;
152 }
153
154
133Variable and Function Names 155Variable and Function Names
134--------------------------- 156---------------------------
135 157
@@ -155,6 +177,12 @@ Tip and Pointers
155 177
156The following are simple coding guidelines that should be followed: 178The following are simple coding guidelines that should be followed:
157 179
180 - When in doubt about the propper behavior of a busybox program (output,
181 formatting, options, etc.), model it after the equivalent GNU program.
182 Doesn't matter how that program behaves on some other flavor of *NIX;
183 doesn't matter what the POSIX standard says or doesn't say, just model
184 busybox programs after their GNU counterparts and nobody has to get hurt.
185
158 - Don't use a '#define var 80' when you can use 'static const int var 80' 186 - Don't use a '#define var 80' when you can use 'static const int var 80'
159 instead. This makes the compiler do typechecking for you (rather than 187 instead. This makes the compiler do typechecking for you (rather than
160 relying on the more error-prone preprocessor) and it makes debugging 188 relying on the more error-prone preprocessor) and it makes debugging