Development Team/Coding Standards
The following are a set of standards that should be adhered to when writing patches for ircd-darenet and services-darenet. Since these programs are based on the works of other's (outside of the DareNET development team), not all code will follow them. This, of course, will be rectified with time.
In This Guide: |
Comments
Comment your code when you do something that someone else may think is not trivial.
Multiple Line
Multiple line comments should follow the C-style comment, for example: <source lang="c" line start=1 > /**
* This is a multiple line comment. * - SecretAgent */</source>
Single Line
Single line comments should also be in the C style, for example: <source lang="c" line start=1 > /* This is a one-line comment. - SecretAgent */</source>
Indentation
Tabs. Tabs. ONLY TABS.
Use a single tab for each level of indentation, for example: <source lang="c" line start=1 > int main() {
if (condition) { code }
}</source>
Separation
Always put a space in between a keyword like if/while and the condition, for example:
<source lang="c" line start=1 >if (foo == bar)</source>
NOT
<source lang="c" line start=1 >if(foo == bar)</source>
Braces
Always put braces opening and closing blocks on separate lines, see the indentation example.
For example, place braces like this: <source lang="c" line start=1 > if (apples == "green") {
cout << "Apples are green" << endl;
}</source>
and NOT: <source lang="c" line start=1 > if (apples == "green") {
cout << "Apples are green" << endl;
}</source>
The one exception to this is if you are declaring a class method which is only one line long, in that case the following is acceptable in most cases: <source lang="c" line start=1 > class foo : public bar {
foo() { } getrandomfoo() { return rand(); }
};</source>
Templates
Where possible, use templates rather than #defines.
Variable naming
Class and struct names should be in camel case with a leading capital letter, for example, "MyBagOfBanes." Variable names can be either in camel case with a leading capital letter or alternatively all lower case, so long as the same naming convention is adhered to throughout the class. Constants and enum values should always be completely in CAPITALS and underscores may be used.
Use of char pointers
Whenever you use char pointers (char*, char**) try to use const equivalents. This is much safer and avoids ugly and dangerous casts.
Linefeeds
Unix linefeeds only please. We do not like to see our screens covered in ^M.
Additionally, the maximum line width is 80 characters. If you are writing a longer line, try to break it at a logical point and continue on the next line with the same indenting. Use of backslash is okay; however, multi-line literals might cause less confusion if they are defined before the function start.
Portability
Always make sure your code is portable to all supported operating systems. Don't write code that only works on Linux. Test your code on all platforms or ask for help from other developers who have the platforms you want to test on.
External Dependencies
You must not use any dependencies that are not available as standard on all supported operating systems beyond libc, and whatever else is currently needed to build the ircd/services. If you absolutely must do so, you will need approval from the Development Manager first.
Profiling and Performance
It is one thing to assume that code performs bad, it is another thing to prove that it actually is. A lot of experienced programmers talk about 'premature optimization', and here is what it means: if you have a piece of code called once on start up that takes 10 seconds instead of one second to run, and a piece of code that takes 0.05 seconds to run when it should take 0.01, and it is called once per second, the second piece of code is the priority.
In other words, make sure that what you think is slow, and a performance problem in ircd-*/services-* actually is.
more to come, possibly...