Difference between revisions of "Coding Style"

1,971 bytes added ,  18:13, 13 September 2022
m
Text replacement - "^" to "{{deprecated}}"
(Created page with "= Coding style for C and C++ = 1. Function names: each word in function name should start with capital letter. No underscores. For example: '''CreateNewUser'''. Underscores a...")
 
m (Text replacement - "^" to "{{deprecated}}")
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Coding style for C and C++ =
{{deprecated}}= Coding style for C and C++ =


1. Function names: each word in function name should start with capital letter. No underscores. For example: '''CreateNewUser'''. Underscores allowed in parameter handlers, which can start with '''H_''' prefix, like this: '''H_FreeDiskSpace'''.
1. Function names: each word in function name should start with capital letter. No underscores. For example: '''CreateNewUser'''. Underscores allowed in parameter handlers, which can start with '''H_''' prefix, like this: '''H_FreeDiskSpace'''.


2. Class names: each word in class name should start with capital letter. No underscores. For example: '''NetworkService'''.
2. Class names: each word in class name should start with capital letter. No underscores. For example: '''NetworkService'''. Consecutive capital letters should be avoided, i.e. use '''SnmpObject''' instead of '''SNMPObject'''.


3. Class methods: each word in methos name should start with capital letter, except first word. No underscores. For example: '''NetworkService::createService()'''.
3. Class methods: each word in method name should start with capital letter, except first word. No underscores. For example: '''NetworkService::createService()'''.


4. Class members: name must start with '''m_''' prefix, each word in member name should start with capital letter, except first word. No underscores. For example: '''NetworkService::m_serviceId'''.
4. Class members: name must start with '''m_''' prefix, each word in member name should start with capital letter, except first word. No underscores. For example: '''NetworkService::m_serviceId'''.
Line 13: Line 13:
6. Opening { should be placed on next line without indentation, like below:
6. Opening { should be placed on next line without indentation, like below:


<syntaxhighlight lang="c">
   if (a < b)
   if (a < b)
   {
   {
       something();
       something();
   }
   }
</syntaxhighlight>


7. Operators and operands should be separated by spaces, like below:
7. Operators and operands should be separated by spaces, like below:


<syntaxhighlight lang="c">
   a = x + 20 / (y - z);
   a = x + 20 / (y - z);
</syntaxhighlight>
   
   
8. Function arguments should be separated by spaces, like below:
8. Function arguments should be separated by spaces, like below:
   
   
<syntaxhighlight lang="c">
   z = function(p1, p2, p3);
   z = function(p1, p2, p3);
</syntaxhighlight>
   
   
9. One-line comments should be placed with the same indentation level as code, like this:
9. One-line comments should be placed with the same indentation level as code, like this:
   
   
<syntaxhighlight lang="c">
   c = xxx();
   c = xxx();
   if (a)
   if (a)
Line 34: Line 41:
       func();
       func();
   }
   }
</syntaxhighlight>
   
   
10. Brackets after for and while operators may or may not be separated by spaces (I prefer not to separate them, but it's not a big problem IMHO).
10. Brackets after for and while operators may or may not be separated by spaces (I prefer not to separate them, but it's not a big problem IMHO).
Line 39: Line 47:
11. For type cast type name must be enclosed in brackets, without spaces. For example: '''(DWORD)x'''.
11. For type cast type name must be enclosed in brackets, without spaces. For example: '''(DWORD)x'''.
   
   
12. It is recommended to use the dollowing typedefs as a replacement for some system data types:
12. It is recommended to use the following typedefs as a replacement for certain system data types:
{| class="wikitable"
{| class="wikitable"
|-
|-
Line 52: Line 60:
| QWORD || instead of system's 64 bit unsigned integer
| QWORD || instead of system's 64 bit unsigned integer
|}
|}
= Coding style for Java =
1. Class names: each word in class name should start with capital letter. No underscores. For example: '''NetworkService'''. Consecutive capital letters should be avoided, i.e. use '''SnmpObject''' instead of '''SNMPObject'''.
2. Interfaces should '''not''' be prefixed with I character.
3. Class members (both methods and attributes): each word in member name should start with capital letter, except first word. No underscores. For example: '''NetworkService.serviceId'''. Consecutive capital letters should be avoided, i.e. use '''getSnmpPort''' instead of '''getSNMPPort'''.
4. Indentation offset: 3
5. Opening { should be placed on next line without indentation, like below:
<syntaxhighlight lang="java">
  if (a < b)
  {
      something();
  }
</syntaxhighlight>
the only exception is anonymous inner class definition, like below:
<syntaxhighlight lang="java">
menuMgr.addMenuListener(new IMenuListener() {
public void menuAboutToShow(IMenuManager mgr)
{
fillContextMenu(mgr);
}
});
</syntaxhighlight>
6. Operators and operands should be separated by spaces, like below:
<syntaxhighlight lang="java">
  a = x + 20 / (y - z);
</syntaxhighlight>
7. Method arguments should be separated by spaces, like below:
<syntaxhighlight lang="java">
  z = method(p1, p2, p3);
</syntaxhighlight>
8. One-line comments should be placed with the same indentation level as code, like this:
<syntaxhighlight lang="java">
  c = xxx();
  if (a)
  {
      // comment
      func();
  }
</syntaxhighlight>
9. Brackets after for and while operators may or may not be separated by spaces (I prefer not to separate them).