File: codingstyle.txt

package info (click to toggle)
debian-installer 20070308etch7
  • links: PTS
  • area: main
  • in suites: etch
  • size: 4,284 kB
  • ctags: 142
  • sloc: xml: 9,843; sh: 1,623; makefile: 784; perl: 496; awk: 100
file content (206 lines) | stat: -rw-r--r-- 5,029 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
Debian-installer style guide
============================

(This guide is ripped off from multiple sources, most notably Busybox's
style guide)

This document describes the coding style conventions used in
debian-installer. If you add a new file to any of the subprojects in
debian-installer or are editing an existing file, please format your code
according to this style. If you are the maintainer of a file that does not
follow these guidelines, please -- at your own convenience -- modify the
file(s) you maintain to bring them into conformance with this style guide.
Please note that this is a low priority task.

Formatting
----------

Line length
~~~~~~~~~~~

Keep line length within 80 characters.
(allow printing on old printers, it means that
inclusion as verbatim text in webpages and other documents is possible)

Tabs vs spaces
~~~~~~~~~~~~~~

d-i does not currently have a well-defined policy on tabs vs. spaces for C
code. Please respect the indentation method used in the file; two are
common:

  1. Indent lines with spaces.  Each indent is four spaces.
  2. Indent blocks with tabs. Use spaces for indentation that is not a code
     block (presentational indentation).

Since shell scripts that are part of the installer should be as small as
possibly to minimise its runtime footprint, and since indenting with spaces
actually makes files larger than indenting with tabs, we do have a
well-defined policy for shell scripts in d-i:

  Indent blocks with tabs. Use spaces (rarely) for presentational indentation.

Any file that contains a combination of two or more indentation types
can be reformatted by anyone who wasn't responsible for it getting into
that messed up state in the first place, using whatever indentation method
they prefer.

Operator Spacing
~~~~~~~~~~~~~~~~

Put spaces between terms and operators. Example:

Don't do this:

      for(i=0;i<num_items;i++){

Do this instead:

      for (i = 0; i < num_items; i++) {

While it extends the line a bit longer, the spaced version is more
readable. An allowable exception to this rule is the situation where
excluding the spacing makes it more obvious that we are dealing with a
single term (even if it is a compound term) such as:

      if (str[idx] == '/' && str[idx-1] != '\\')

or

      if ((argc-1) - (optind+1) > 0)

Bracket Spacing
~~~~~~~~~~~~~~~

If an opening bracket starts a function, it should be on the
next line with no spacing before it. However, if a bracket follows an opening
control block, it should be on the same line with a single space (not a tab)
between it and the opening control block statement. Examples:

Don't do this:

      while (!done)
      {

      do
      {

Don't do this either:

      while (!done){

      do{

And for heaven's sake, don't do this:

      while (!done)
        {

      do
        {

Do this instead:

      while (!done) {

      do {


Spacing around Parentheses
~~~~~~~~~~~~~~~~~~~~~~~~~~

Put a space between C keywords and left parens, but not between function names
and the left paren that starts its parameter list (whether it is being
declared or called). Examples:

Don't do this:

      while(foo) {
      for(i = 0; i < n; i++) {

Do this instead:

      while (foo) {
      for (i = 0; i < n; i++) {

But do functions like this:

      static int my_func(int foo, char bar)
      ...
      baz = my_func(1, 2);

Also, don't put a space between the left paren and the first term, nor between
the last arg and the right paren.

Don't do this:

      if ( x < 1 )
      strcmp( thisstr, thatstr )

Do this instead:

      if (x < 1)
      strcmp (thisstr, thatstr)

Cuddled Elses
~~~~~~~~~~~~~

Also, please "cuddle" your else statements by putting the else keyword on the
same line after the right bracket that closes an 'if' statement.

Don't do this:

      if (foo) {
          stmt;
      }
      else {
          stmt;
      }

Do this instead:

     if (foo) {
         stmt;
     } else {
         stmt;
     }

The exception to this rule is if you want to include a comment before the else
block. Example:

     if (foo) {
         stmts...
     }
     /* otherwise, we're just kidding ourselves, so re-frob the input */
     else {
         other_stmts...
     }

Variable and Function Names
---------------------------

Use the K&R style with names in all lower-case and underscores occasionally
used to separate words (e.g., "variable_name" and "numchars" are both
acceptable). Using underscores makes variable and function names more readable
because it looks like whitespace; using lower-case is easy on the eyes.

        Frowned upon:

                hitList
                TotalChars
                szFileName
                pf_Nfol_TriState

        Preferred:

                hit_list
                total_chars
                file_name
                sensible_name

Exceptions:

 - Enums, macros, and constant variables are occasionally written in all
   upper-case with words optionally separated by underscores (i.e. FIFOTYPE,
   ISBLKDEV()).