source: trunk/CodingConventions.txt@ 118

Last change on this file since 118 was 118, checked in by umoeller, 24 years ago

Tons of changes.

  • Property svn:eol-style set to CRLF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1
2XWorkplace/WarpIN Coding Conventions
3(W) Ulrich M”ller, March 13, 2000
4Last updated January 22, 2001 Ulrich M”ller
5
6When adding code to XWorkplace, WarpIN, or the XWorkplace helpers,
7please follow the coding conventions outlined below.
8
9Yes, I know everyone has his/her favorite coding style. This is
10a likely topic to cause endless debate, but if you contribute to
11my projects... please follow my style.
12
13In addition to consistency, this is very helpful for automatic code
14documentation through xdoc. See tools/xdoc in the WarpIN source tree
15for more about that utility.
16
17Here we go:
18
19 1. Use a tab size of 4. Use real spaces instead of tabs.
20
21 2. Align parameters vertically with function calls, at least
22 in function headers:
23
24 int StoreExecuteRexxCode(const char *pcszName,
25 const char *pcszCode,
26 const char *pcszArgs,
27 char **ppszRet);
28
29 Add xdoc documentation to all functions and parameters,
30 as outlined below.
31
32 3. Brackets style:
33
34 if (condition)
35 {
36 // do this
37 }
38 else
39 {
40 // do that
41 }
42
43 You may leave out brackets if there's only one statement
44 after if or else, of course, but with nested if statements,
45 I usually add them even in that case since it's so easy
46 to mismatch the nesting then.
47
48 4. switch/case style:
49
50 switch (msg)
51 {
52 case WM_CREATE:
53 // code
54 break;
55
56 case WM_DESTROY:
57 // code
58 break;
59 }
60
61 5. For all variables, use the usual OS/2 type prefixes.
62 Here are some:
63
64 CHAR c (char)
65 PSZ psz (char* pointer)
66 PCSZ pcsz (const char* pointer)
67
68 USHORT us (unsigned short)
69 SHORT s (short)
70 ULONG ul (unsigned long)
71 LONG l (long)
72 BYTE b (byte)
73
74 BOOL f (flag)
75 LONG fl (for LONG's containing OR'ed flags)
76 SHORT fs (for SHORT's containing OR'ed flags)
77
78 string/BSString str (C++ string class instance)
79
80 For arrays, prefix "a" (e.g. USHORT ausThings[3]).
81 For pointers, prefix "p" (e.g. USHORT *pausThings[3]).
82
83 6. Prefix C++ class member variables with an underscore ("_").
84 This allows people who are not familiar with the class
85 interface to identify member variables easily. Also, this
86 has a certain consistency with SOM/WPS class member
87 variables.
88
89 7. Prefix global variables with "G_" for the same reason.
90 Global variables are potentially dangerous, so these
91 can be more easily identified.
92
93 8. Comment your functions in xdoc-style. See any function
94 in the sources for how this can be done. Basically, use
95 /* */-style comments before the function header and
96 xdoc tags in that block.
97
98 Sorta like this:
99
100 /*
101 *@@ Create:
102 * create something.
103 */
104
105 PVOID Create(PVOID pvCreateFrom, // in: create from
106 PULONG pulCount) // out: new count
107 {
108 ... // code, ignored by xdoc
109 }
110
111 xdoc will even take the parameter descriptions if they
112 are specified as above.
113
114 tools/xdoc/readme.txt in the WarpIN sources has a more
115 detailed description.
116
117 I usually only document functions in the source files,
118 not in the headers. Even though xdoc will find documentation
119 in headers also, changing headers causes recompiles,
120 especially with the complex include hierarchy of WarpIN.
121 Also, changing code documentation in the sources only
122 reduces the amount of code which needs to be committed
123 to the CVS server.
124
125 9. When changing code, mark the code as changed in the
126 xdoc comment by using something like the following:
127
128 @@changed V0.9.2 (2000-03-10) [umoeller]: fixed memory leak
129 | | | | |
130 | | | | +-- description
131 | | | |
132 | | | +- author tag (same as CVS login)
133 | | |
134 | | +-- ISO date (year, month, day)
135 | |
136 | +-- XWorkplace/WarpIN version number
137 |
138 +-- xdoc tag ("@@changed" or "@@added")
139
140 xdoc can create a full change log if these things are set
141 properly. Try "createdoc.cmd" in the WarpIN and XWorkplace
142 main source directories, respectively.
143
144 Also, this way I can do a simple search over all files
145 to update the readme with changes and bugfixes for the new
146 version.
147
148 10. When adding a new function, use the same, just use @@added
149 instead of @@changed.
150
151Thank you!
152
153
Note: See TracBrowser for help on using the repository browser.