aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Whitley <markw@lineo.com>2000-11-17 21:28:39 +0000
committerMark Whitley <markw@lineo.com>2000-11-17 21:28:39 +0000
commit9028e2c96aa2e8a863c8ad9aa3e870fc160f1c23 (patch)
treef7141748a3e82bd013163e218c9d744b9dd4d2a0
parenta683ee81d918f338a8335d4f03057106b701afec (diff)
downloadbusybox-w32-9028e2c96aa2e8a863c8ad9aa3e870fc160f1c23.tar.gz
busybox-w32-9028e2c96aa2e8a863c8ad9aa3e870fc160f1c23.tar.bz2
busybox-w32-9028e2c96aa2e8a863c8ad9aa3e870fc160f1c23.zip
Numerous spelling / grammar corrections from Larry Doolittle
<ldoolitt@recycle.lbl.gov>, as well as a few additions / clarifications.
-rw-r--r--docs/style-guide.txt79
1 files changed, 52 insertions, 27 deletions
diff --git a/docs/style-guide.txt b/docs/style-guide.txt
index 72d3b9375..36974d7f5 100644
--- a/docs/style-guide.txt
+++ b/docs/style-guide.txt
@@ -21,11 +21,12 @@ Declaration Order
21 21
22Here is the order in which code should be laid out in a file: 22Here is the order in which code should be laid out in a file:
23 23
24 - commented program name and one-line description
24 - commented author name and email address(es) 25 - commented author name and email address(es)
25 - commented GPL boilerplate 26 - commented GPL boilerplate
26 - commented description of program 27 - commented longer description / notes for the program (if needed)
27 - #includes and #defines 28 - #includes and #defines
28 - const and globals variables 29 - const and global variables
29 - function declarations (if necessary) 30 - function declarations (if necessary)
30 - function implementations 31 - function implementations
31 32
@@ -37,7 +38,7 @@ This is everybody's favorite flame topic so let's get it out of the way right
37up front. 38up front.
38 39
39 40
40Tabs vs Spaces in Line Indentation 41Tabs vs. Spaces in Line Indentation
41~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 42~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
42 43
43The preference in Busybox is to indent lines with tabs. Do not indent lines 44The preference in Busybox is to indent lines with tabs. Do not indent lines
@@ -56,7 +57,7 @@ multi-line comments that use an asterisk at the beginning of each line, i.e.:
56 57
57Furthermore, The preference is that tabs be set to display at four spaces 58Furthermore, The preference is that tabs be set to display at four spaces
58wide, but the beauty of using only tabs (and not spaces) at the beginning of 59wide, but the beauty of using only tabs (and not spaces) at the beginning of
59lines is that you can set your editor to display tabs at *watever* number of 60lines is that you can set your editor to display tabs at *whatever* number of
60spaces is desired and the code will still look fine. 61spaces is desired and the code will still look fine.
61 62
62 63
@@ -76,7 +77,7 @@ Put spaces between terms and operators. Example:
76 While it extends the line a bit longer, the spaced version is more 77 While it extends the line a bit longer, the spaced version is more
77 readable. An allowable exception to this rule is the situation where 78 readable. An allowable exception to this rule is the situation where
78 excluding the spacing makes it more obvious that we are dealing with a 79 excluding the spacing makes it more obvious that we are dealing with a
79 single term (even if it is a compund term) such as: 80 single term (even if it is a compound term) such as:
80 81
81 if (str[idx] == '/' && str[idx-1] != '\\') 82 if (str[idx] == '/' && str[idx-1] != '\\')
82 83
@@ -89,12 +90,20 @@ Bracket Spacing
89~~~~~~~~~~~~~~~ 90~~~~~~~~~~~~~~~
90 91
91If an opening bracket starts a function, it should be on the 92If an opening bracket starts a function, it should be on the
92next line with no spacing before it. However, if a bracet follows an opening 93next line with no spacing before it. However, if a bracket follows an opening
93control block, it should be on the same line with a single space (not a tab) 94control block, it should be on the same line with a single space (not a tab)
94between it and the opening control block statment. Examples: 95between it and the opening control block statement. Examples:
95 96
96 Don't do this: 97 Don't do this:
97 98
99 while (!done)
100 {
101
102 do
103 {
104
105 Don't do this either:
106
98 while (!done){ 107 while (!done){
99 do{ 108 do{
100 109
@@ -121,7 +130,7 @@ is being declared or called). Examples:
121 while (foo) { 130 while (foo) {
122 for (i = 0; i < n; i++) { 131 for (i = 0; i < n; i++) {
123 132
124 Do functions like this: 133 But do functions like this:
125 134
126 static int my_func(int foo, char bar) 135 static int my_func(int foo, char bar)
127 ... 136 ...
@@ -131,8 +140,8 @@ is being declared or called). Examples:
131Cuddled Elses 140Cuddled Elses
132~~~~~~~~~~~~~ 141~~~~~~~~~~~~~
133 142
134Also, please "cuddle" your else statments by putting the else keyword on the 143Also, please "cuddle" your else statements by putting the else keyword on the
135same line after the right bracket that closes an 'if' statment. 144same line after the right bracket that closes an 'if' statement.
136 145
137 Don't do this: 146 Don't do this:
138 147
@@ -151,25 +160,36 @@ same line after the right bracket that closes an 'if' statment.
151 stmt; 160 stmt;
152 } 161 }
153 162
163The exception to this rule is if you want to include a comment before the else
164block. Example:
165
166 if (foo) {
167 stmts...
168 }
169 /* otherwise, we're just kidding ourselves, so re-frob the input */
170 else {
171 other_stmts...
172 }
173
154 174
155Variable and Function Names 175Variable and Function Names
156--------------------------- 176---------------------------
157 177
158Use the K&R style with names in all lower-case and underscores occasionally 178Use the K&R style with names in all lower-case and underscores occasionally
159used to seperate words (e.g. "variable_name" and "numchars" are both 179used to separate words (e.g., "variable_name" and "numchars" are both
160acceptable). Using underscores makes variable and function names more readable 180acceptable). Using underscores makes variable and function names more readable
161because it looks like whitespace; using lower-case is easy on the eyes. 181because it looks like whitespace; using lower-case is easy on the eyes.
162 182
163Note: The Busybox codebase is very much a mixture of code gathered from a 183Note: The Busybox codebase is very much a mixture of code gathered from a
164variety of locations. This explains why the current codebase contains such a 184variety of sources. This explains why the current codebase contains such a
165plethora of different naming styles (Java, Pascal, K&R, just-plain-weird, 185hodge-podge of different naming styles (Java, Pascal, K&R, just-plain-weird,
166etc.). The K&R guideline explained above should therefore be used on new files 186etc.). The K&R guideline explained above should therefore be used on new files
167that are added to the repository. Furthermore, the maintainer of an existing 187that are added to the repository. Furthermore, the maintainer of an existing
168file that uses alternate naming conventions should -- at his own convenience 188file that uses alternate naming conventions should -- at his own convenience --
169-- convert those names over to K&R style; converting variable names is a very 189convert those names over to K&R style; converting variable names is a very low
170low priority task. Perhaps in the future we will include some magical Perl 190priority task. Perhaps in the future we will include some magical Perl script
171script that can go through and convert files--left as an exersize to the 191that can go through and convert files -- left as an exercise to the reader for
172reader. 192now.
173 193
174 194
175Tip and Pointers 195Tip and Pointers
@@ -177,31 +197,34 @@ Tip and Pointers
177 197
178The following are simple coding guidelines that should be followed: 198The following are simple coding guidelines that should be followed:
179 199
180 - When in doubt about the propper behavior of a busybox program (output, 200 - When in doubt about the proper behavior of a Busybox program (output,
181 formatting, options, etc.), model it after the equivalent GNU program. 201 formatting, options, etc.), model it after the equivalent GNU program.
182 Doesn't matter how that program behaves on some other flavor of *NIX; 202 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 203 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. 204 Busybox programs after their GNU counterparts and nobody has to get hurt.
185 205
186 - Don't use a '#define var 80' when you can use 'static const int var 80' 206 - Don't use a '#define var 80' when you can use 'static const int var 80'
187 instead. This makes the compiler do typechecking for you (rather than 207 instead. This makes the compiler do type checking for you (rather than
188 relying on the more error-prone preprocessor) and it makes debugging 208 relying on the more error-prone preprocessor) and it makes debugging
189 programs much easier since the value of the variable can be easily queried. 209 programs much easier since the value of the variable can be easily
210 displayed.
190 211
191 - If a const variable is used in only one function, do not make it global to 212 - If a const variable is used in only one function, do not make it global to
192 the file. Instead, declare it inside the function body. 213 the file. Instead, declare it inside the function body.
193 214
194 - Inside applet files, all functions should be declared static so as to keep 215 - Inside applet files, all functions should be declared static so as to keep
195 the global namespace clean. The only exception to this rule is the 216 the global name space clean. The only exception to this rule is the
196 "applet_main" function which must be declared extern. 217 "applet_main" function which must be declared extern.
197 218
198 - If you write a function that performs a task that could be useful outside 219 - If you write a function that performs a task that could be useful outside
199 the immediate file, turn it into a general-purpose function with no ties to 220 the immediate file, turn it into a general-purpose function with no ties to
200 any applet and put it in the utility.c file instead. 221 any applet and put it in the utility.c file instead.
201 222
202 - Put all help/usage messages in usage.c. Put other strings in messages.c 223 - Put all help/usage messages in usage.c. Put other strings in messages.c.
203 (Side Note: we might want to use a single file instead of two, food for 224 Putting these strings into their own file is a calculated decision designed
204 thought). 225 to confine spelling errors to a single place and aid internationalization
226 efforts, if needed. (Side Note: we might want to use a single file instead
227 of two, food for thought).
205 228
206 - There's a right way and a wrong way to test for sting equivalence with 229 - There's a right way and a wrong way to test for sting equivalence with
207 strcmp: 230 strcmp:
@@ -218,7 +241,9 @@ The following are simple coding guidelines that should be followed:
218 241
219 The use of the "equals" (==) operator in the latter example makes it much 242 The use of the "equals" (==) operator in the latter example makes it much
220 more obvious that you are testing for equivalence. The former example with 243 more obvious that you are testing for equivalence. The former example with
221 the "not" (!) operator makes it look like you are testing for an error. 244 the "not" (!) operator makes it look like you are testing for an error. In
245 a more perfect world, we would have a streq() function in the string
246 library, but that ain't the world we're living in.
222 247
223 - Do not use old-style function declarations that declare variable types 248 - Do not use old-style function declarations that declare variable types
224 between the parameter list and opening bracket. Example: 249 between the parameter list and opening bracket. Example: