Jump to content

Macaw-Movies/Development/Code Rules: Difference between revisions

From KDE Community Wiki
Ochurlaud (talk | contribs)
Created page with "== Naming == * English is used for all names (class, function, variable…) * camelCase is used for all names === Variables === * Abreviations are not tolerated anywhere in t..."
 
Ochurlaud (talk | contribs)
Line 18: Line 18:
=== Conditions ===
=== Conditions ===
The following rules sould be followed (1 space after key word, 1 between condition and curly bracket).
The following rules sould be followed (1 space after key word, 1 between condition and curly bracket).
{{Input|<syntaxhighlight lang="javascript" line>
{{Input|<syntaxhighlight lang="cpp-qt" line>
if (variable > 0) {
if (variable > 0) {
     ...do something...
     ...do something...
Line 28: Line 28:
</syntaxhighlight>}}
</syntaxhighlight>}}
If there is more conditions to fulfill:
If there is more conditions to fulfill:
{{Input|<syntaxhighlight lang="javascript" line>
{{Input|<syntaxhighlight lang="cpp-qt" line>
if (cond1
if (cond1
   & cond2) {
   & cond2) {
Line 35: Line 35:
</syntaxhighlight>}}
</syntaxhighlight>}}
For the switch/case:  
For the switch/case:  
{{Input|<syntaxhighlight lang="javascript" line>
{{Input|<syntaxhighlight lang="cpp-qt" line>
switch (var)
switch (var)
{
{

Revision as of 22:20, 26 February 2015

Naming

  • English is used for all names (class, function, variable…)
  • camelCase is used for all names

Variables

  • Abreviations are not tolerated anywhere in the code. All names must be as explicit as possible
  • members start with `m_`
  • local variables start with `l_`
  • function parameter names do not have a specific prefix
  • global variables are prohibited, the few accepted are capitalized
  • class names start with a capital letter

Functions

  • blank line before calling return
  • blank line between two logical blocs


Conditions

The following rules sould be followed (1 space after key word, 1 between condition and curly bracket).

if (variable > 0) {
    ...do something...
} else if (variable == 0) {
    ...do something else...
} else {
    ...do something else...
}

If there is more conditions to fulfill:

if (cond1
   & cond2) {
    ...do something...
}

For the switch/case:

switch (var)
{
case 1:
    fct();
    break;
case 2:
    otherFct();
    break;
}