| 1 |
libabw coding style |
| 2 |
------------------- |
| 3 |
|
| 4 |
Indentation/spacing: We indent with tabs. Not spaces. This decision is, of |
| 5 |
course, rather contentious, but it does have the force of inertia going for |
| 6 |
it. Try to keep lines less than 120 columns wide. Please run |
| 7 |
|
| 8 |
astyle --options=astyle.options \*.h \*.cpp |
| 9 |
|
| 10 |
before committing. |
| 11 |
|
| 12 |
Naming: Version-specific classes, enumerations, and defines should be prefixed |
| 13 |
with 'WP', followed by the version number (e.g.: WP6, WP5, WP51, etc.). |
| 14 |
Generic classes (this includes utility abstractions like streams and strings) |
| 15 |
should be prefixed with WPX. |
| 16 |
|
| 17 |
For better worse, we have decided on using the camel caps convention for naming |
| 18 |
variables (i.e.: tempJustification). Use of hungarian notation (i.e.: iNum) is |
| 19 |
forbidden, with one exception: use the 'm_' prefix for naming class and struct |
| 20 |
variables (i.e.: my_class->m_var). Short-hand for variable names is allowed, |
| 21 |
but don't overdo it (m_var->len() instead of m_variable->length() is ok, |
| 22 |
m_nam instead of m_name is stupid). For AbiWord-specific state, err on the |
| 23 |
side of verbosity (e.g.: names like |
| 24 |
WP6ParagraphGroup_RightMarginAdjustmentSubGroup are _good_), as the extra |
| 25 |
contextual information is useful when trying to decipher a convoluted piece of |
| 26 |
code in the libabw parser. |
| 27 |
|
| 28 |
Memory allocation: Use the C++ standard operations for this (new, delete). |
| 29 |
The rare use of realloc (and consequent use of malloc and free) in special |
| 30 |
cases is allowed (although using a data structure from the C++ standard library |
| 31 |
is almost always preferable): take care not to mix and match C and C++ memory |
| 32 |
allocation functions in this case. |
| 33 |
|
| 34 |
Data structures: Use the C++ standard library wherever appropriate and |
| 35 |
convenient. It should almost never be necessary to roll your own data |
| 36 |
structure. |
| 37 |
|
| 38 |
Strings: You may use either the C++ standard strings or our very own |
| 39 |
UTF8-compliant WPXString. Hand-allocated char *'s are discouraged. |
| 40 |
|
| 41 |
Further information: The OpenOffice.org (http://tools.openoffice.org/coding.html) |
| 42 |
and AbiWord (cvs://cvs.abisource.com/abi/docs/AbiSourceCodeGuidelines.abw) |
| 43 |
contain lots of useful information that will make you a better C++ coder. |
| 44 |
Follow their advice religiously, except when they contradict something in this |
| 45 |
document. |
| 46 |
|
| 47 |
Fun: Remember, the important thing is to have fun. :-) These rules are a means, |
| 48 |
not an end. Happy hacking! |