diff options
author | Mark Whitley <markw@lineo.com> | 2000-11-17 21:28:39 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2000-11-17 21:28:39 +0000 |
commit | 9028e2c96aa2e8a863c8ad9aa3e870fc160f1c23 (patch) | |
tree | f7141748a3e82bd013163e218c9d744b9dd4d2a0 | |
parent | a683ee81d918f338a8335d4f03057106b701afec (diff) | |
download | busybox-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.txt | 79 |
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 | ||
22 | Here is the order in which code should be laid out in a file: | 22 | Here 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 | |||
37 | up front. | 38 | up front. |
38 | 39 | ||
39 | 40 | ||
40 | Tabs vs Spaces in Line Indentation | 41 | Tabs vs. Spaces in Line Indentation |
41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 42 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
42 | 43 | ||
43 | The preference in Busybox is to indent lines with tabs. Do not indent lines | 44 | The 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 | ||
57 | Furthermore, The preference is that tabs be set to display at four spaces | 58 | Furthermore, The preference is that tabs be set to display at four spaces |
58 | wide, but the beauty of using only tabs (and not spaces) at the beginning of | 59 | wide, but the beauty of using only tabs (and not spaces) at the beginning of |
59 | lines is that you can set your editor to display tabs at *watever* number of | 60 | lines is that you can set your editor to display tabs at *whatever* number of |
60 | spaces is desired and the code will still look fine. | 61 | spaces 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 | ||
91 | If an opening bracket starts a function, it should be on the | 92 | If an opening bracket starts a function, it should be on the |
92 | next line with no spacing before it. However, if a bracet follows an opening | 93 | next line with no spacing before it. However, if a bracket follows an opening |
93 | control block, it should be on the same line with a single space (not a tab) | 94 | control block, it should be on the same line with a single space (not a tab) |
94 | between it and the opening control block statment. Examples: | 95 | between 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: | |||
131 | Cuddled Elses | 140 | Cuddled Elses |
132 | ~~~~~~~~~~~~~ | 141 | ~~~~~~~~~~~~~ |
133 | 142 | ||
134 | Also, please "cuddle" your else statments by putting the else keyword on the | 143 | Also, please "cuddle" your else statements by putting the else keyword on the |
135 | same line after the right bracket that closes an 'if' statment. | 144 | same 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 | ||
163 | The exception to this rule is if you want to include a comment before the else | ||
164 | block. 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 | ||
155 | Variable and Function Names | 175 | Variable and Function Names |
156 | --------------------------- | 176 | --------------------------- |
157 | 177 | ||
158 | Use the K&R style with names in all lower-case and underscores occasionally | 178 | Use the K&R style with names in all lower-case and underscores occasionally |
159 | used to seperate words (e.g. "variable_name" and "numchars" are both | 179 | used to separate words (e.g., "variable_name" and "numchars" are both |
160 | acceptable). Using underscores makes variable and function names more readable | 180 | acceptable). Using underscores makes variable and function names more readable |
161 | because it looks like whitespace; using lower-case is easy on the eyes. | 181 | because it looks like whitespace; using lower-case is easy on the eyes. |
162 | 182 | ||
163 | Note: The Busybox codebase is very much a mixture of code gathered from a | 183 | Note: The Busybox codebase is very much a mixture of code gathered from a |
164 | variety of locations. This explains why the current codebase contains such a | 184 | variety of sources. This explains why the current codebase contains such a |
165 | plethora of different naming styles (Java, Pascal, K&R, just-plain-weird, | 185 | hodge-podge of different naming styles (Java, Pascal, K&R, just-plain-weird, |
166 | etc.). The K&R guideline explained above should therefore be used on new files | 186 | etc.). The K&R guideline explained above should therefore be used on new files |
167 | that are added to the repository. Furthermore, the maintainer of an existing | 187 | that are added to the repository. Furthermore, the maintainer of an existing |
168 | file that uses alternate naming conventions should -- at his own convenience | 188 | file 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 | 189 | convert those names over to K&R style; converting variable names is a very low |
170 | low priority task. Perhaps in the future we will include some magical Perl | 190 | priority task. Perhaps in the future we will include some magical Perl script |
171 | script that can go through and convert files--left as an exersize to the | 191 | that can go through and convert files -- left as an exercise to the reader for |
172 | reader. | 192 | now. |
173 | 193 | ||
174 | 194 | ||
175 | Tip and Pointers | 195 | Tip and Pointers |
@@ -177,31 +197,34 @@ Tip and Pointers | |||
177 | 197 | ||
178 | The following are simple coding guidelines that should be followed: | 198 | The 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: |