diff options
author | Mark Whitley <markw@lineo.com> | 2000-08-22 00:20:21 +0000 |
---|---|---|
committer | Mark Whitley <markw@lineo.com> | 2000-08-22 00:20:21 +0000 |
commit | 2368a387edced9e9722d6b8e7a82bd2e191ca347 (patch) | |
tree | 6123b4d69633c0953caba7cfe791b3d8f16ec9ba | |
parent | e4c4d69c0488f554bc2dbb8cd1ea7deff0da3214 (diff) | |
download | busybox-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.txt | 84 |
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 | |||
15 | right formatting rules to your file. Please _do_not_ run this on all the files | 15 | right formatting rules to your file. Please _do_not_ run this on all the files |
16 | in the directory, just your own. | 16 | in the directory, just your own. |
17 | 17 | ||
18 | |||
18 | Declaration Order | 19 | Declaration 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 | |||
31 | Whitespace | 33 | Whitespace |
32 | ---------- | 34 | ---------- |
33 | 35 | ||
34 | Tabs vs Spaces in Line Indentation: The preference in Busybox is to indent | 36 | This is everybody's favorite flame topic so let's get it out of the way right |
35 | lines with tabs. Do not indent lines with spaces and do not indents lines | 37 | up front. |
36 | using a mixture of tabs and spaces. (The indentation style in the Apache and | 38 | |
37 | Postfix source does this sort of thing: \s\s\s\sif (expr) {\n\tstmt; --ick.) | 39 | |
38 | The only exception to this rule is multi-line comments that use an asterisk at | 40 | Tabs vs Spaces in Line Indentation |
39 | the beginning of each line, i.e.: | 41 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
42 | |||
43 | The preference in Busybox is to indent lines with tabs. Do not indent lines | ||
44 | with spaces and do not indents lines using a mixture of tabs and spaces. (The | ||
45 | indentation 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 | ||
47 | multi-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 | |||
52 | spaces is desired and the code will still look fine. | 60 | spaces is desired and the code will still look fine. |
53 | 61 | ||
54 | 62 | ||
55 | Operator Spacing: Put spaces between terms and operators. Example: | 63 | Operator Spacing |
64 | ~~~~~~~~~~~~~~~~ | ||
65 | |||
66 | Put 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 | ||
77 | Bracket Spacing: If an opening bracket starts a function, it should be on the | 88 | Bracket Spacing |
89 | ~~~~~~~~~~~~~~~ | ||
90 | |||
91 | If an opening bracket starts a function, it should be on the | ||
78 | next line with no spacing before it. However, if a bracet follows an opening | 92 | next line with no spacing before it. However, if a bracet follows an opening |
79 | control block, it should be on the same line with a single space (not a tab) | 93 | control block, it should be on the same line with a single space (not a tab) |
80 | between it and the opening control block statment. Examples: | 94 | between 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 | ||
92 | Also, please "cuddle" your else statments by putting the else keyword on the | ||
93 | same 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 | ||
107 | Paren Spacing | ||
108 | ~~~~~~~~~~~~~ | ||
112 | 109 | ||
113 | Paren Spacing: Put a space between C keywords and left parens, but not between | 110 | Put a space between C keywords and left parens, but not between |
114 | function names and the left paren that starts it's parameter list (whether it | 111 | function names and the left paren that starts it's parameter list (whether it |
115 | is being declared or called). Examples: | 112 | is 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 | |||
131 | Cuddled Elses | ||
132 | ~~~~~~~~~~~~~ | ||
133 | |||
134 | Also, please "cuddle" your else statments by putting the else keyword on the | ||
135 | same 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 | |||
133 | Variable and Function Names | 155 | Variable and Function Names |
134 | --------------------------- | 156 | --------------------------- |
135 | 157 | ||
@@ -155,6 +177,12 @@ Tip and Pointers | |||
155 | 177 | ||
156 | The following are simple coding guidelines that should be followed: | 178 | The 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 |