1 |
|
---|
2 | XWorkplace/WarpIN Coding Conventions
|
---|
3 | (W) Ulrich Mller, March 13, 2000
|
---|
4 | Last updated January 22, 2001 Ulrich Mller
|
---|
5 |
|
---|
6 | When adding code to XWorkplace, WarpIN, or the XWorkplace helpers,
|
---|
7 | please follow the coding conventions outlined below.
|
---|
8 |
|
---|
9 | Yes, I know everyone has his/her favorite coding style. This is
|
---|
10 | a likely topic to cause endless debate, but if you contribute to
|
---|
11 | my projects... please follow my style.
|
---|
12 |
|
---|
13 | In addition to consistency, this is very helpful for automatic code
|
---|
14 | documentation through xdoc. See tools/xdoc in the WarpIN source tree
|
---|
15 | for more about that utility.
|
---|
16 |
|
---|
17 | Here 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. For all variables, use the usual OS/2 type prefixes.
|
---|
33 | Here are some:
|
---|
34 |
|
---|
35 | CHAR c (char)
|
---|
36 | PSZ psz (char* pointer)
|
---|
37 | PCSZ pcsz (const char* pointer)
|
---|
38 |
|
---|
39 | USHORT us (unsigned short)
|
---|
40 | SHORT s (short)
|
---|
41 | ULONG ul (unsigned long)
|
---|
42 | LONG l (long)
|
---|
43 | BYTE b (byte)
|
---|
44 |
|
---|
45 | BOOL f (flag)
|
---|
46 | LONG fl (for LONG's containing OR'ed flags)
|
---|
47 | SHORT fs (for SHORT's containing OR'ed flags)
|
---|
48 |
|
---|
49 | string/ BSString str (C++ string class instance)
|
---|
50 |
|
---|
51 | For arrays, prefix "a" (e.g. USHORT ausThings[3]).
|
---|
52 | For pointers, prefix "p" (e.g. USHORT *pausThings[3]).
|
---|
53 |
|
---|
54 | 4. Prefix C++ class member variables with an underscore ("_").
|
---|
55 | This allows people who are not familiar with the class
|
---|
56 | interface to identify member variables easily. Also, this
|
---|
57 | has a certain consistency with SOM/WPS class member
|
---|
58 | variables.
|
---|
59 |
|
---|
60 | 5. Prefix global variables with "G_" for the same reason.
|
---|
61 | Global variables are potentially dangerous, so these
|
---|
62 | can be more easily identified.
|
---|
63 |
|
---|
64 | 6. Comment your functions in xdoc-style. See any function
|
---|
65 | in the sources for how this can be done. Basically, use
|
---|
66 | /* */-style comments before the function header and
|
---|
67 | xdoc tags in that block.
|
---|
68 |
|
---|
69 | Sorta like this:
|
---|
70 |
|
---|
71 | /*
|
---|
72 | *@@ Create:
|
---|
73 | * create something.
|
---|
74 | */
|
---|
75 |
|
---|
76 | PVOID Create(PVOID pvCreateFrom, // in: create from
|
---|
77 | PULONG pulCount) // out: new count
|
---|
78 | {
|
---|
79 | ... // code, ignored by xdoc
|
---|
80 | }
|
---|
81 |
|
---|
82 | xdoc will even take the parameter descriptions if they
|
---|
83 | are specified as above.
|
---|
84 |
|
---|
85 | tools/xdoc/readme.txt in the WarpIN sources has a more
|
---|
86 | detailed description.
|
---|
87 |
|
---|
88 | I usually only document functions in the source files,
|
---|
89 | not in the headers. Even though xdoc will find documentation
|
---|
90 | in headers also, changing headers causes recompiles,
|
---|
91 | especially with the complex include hierarchy of WarpIN.
|
---|
92 | Also, changing code documentation in the sources only
|
---|
93 | reduces the amount of code which needs to be committed
|
---|
94 | to the CVS server.
|
---|
95 |
|
---|
96 | 7. When changing code, mark the code as changed in the
|
---|
97 | xdoc comment by using something like the following:
|
---|
98 |
|
---|
99 | @@changed V0.9.2 (2000-03-10) [umoeller]: fixed memory leak
|
---|
100 | | | | | |
|
---|
101 | | | | | +-- description
|
---|
102 | | | | |
|
---|
103 | | | | +- author tag (same as CVS login)
|
---|
104 | | | |
|
---|
105 | | | +-- ISO date (year, month, day)
|
---|
106 | | |
|
---|
107 | | +-- XWorkplace/WarpIN version number
|
---|
108 | |
|
---|
109 | +-- xdoc tag ("@@changed" or "@@added")
|
---|
110 |
|
---|
111 | xdoc can create a full change log if these things are set
|
---|
112 | properly. Try "createdoc.cmd" in the WarpIN and XWorkplace
|
---|
113 | main source directories, respectively.
|
---|
114 |
|
---|
115 | Also, this way I can do a simple search over all files
|
---|
116 | to update the readme with changes and bugfixes for the new
|
---|
117 | version.
|
---|
118 |
|
---|
119 | 8. When adding a new function, use the same, just use @@added
|
---|
120 | instead of @@changed.
|
---|
121 |
|
---|
122 | Thank you!
|
---|
123 |
|
---|
124 |
|
---|