Difference between revisions of "Phobos coding conventions"

From D Wiki
Jump to: navigation, search
(line length)
Line 1: Line 1:
 
If you're planning to submit [[Pull Requests|pull requests]] for druntime or Phobos, you should follow the following coding conventions:
 
If you're planning to submit [[Pull Requests|pull requests]] for druntime or Phobos, you should follow the following coding conventions:
  
* Avoid using the tab character.
+
* Style
* Use 4-space indentation.
+
** Avoid using the tab character.
* For blocks enclosed by curly braces ({}), the opening and closing braces should be on their own lines, at the same indentation level as its containing block:
+
** Use 4-space indentation.
 +
** Put a single splace between an {{code|if}} and it's corresponding parenthesis. Eg: {{code|if (condition)}}
 +
** For blocks enclosed by curly braces ({{code|{{()}}}}), the opening and closing braces should be on their own lines, at the same indentation level as its containing block:
 
<syntaxhighlight lang="d">
 
<syntaxhighlight lang="d">
 
void main(string[] args)
 
void main(string[] args)
Line 17: Line 19:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
* Identifiers should use camelcase instead of underscores: myVariable instead of my_variable.
 
* Lines should preferably not be longer than 80 characters, though this is a soft limit.
 
  
In general, just like in any collaborative project, try your best to conform to the same coding style as in the rest of the source file you're editing.
+
* Naming
 +
** Identifiers should use camelcase instead of underscores: {{code|myVariable}} instead of {{code|my_variable}}.
 +
** Types (or templates returning types) should use BumpyCase: {{code|ElementType}} instead of {{code|elementType}} or {{code|element_type}}.
 +
 
 +
* Length of lines:
 +
** Lines should preferably not be longer than 80 characters, though this is a soft limit.
 +
** Documentation should '''never''' be longer than 80 characters. This is a hard limit.
 +
 
 +
Note that this are the guidelines. In general, just like in any collaborative project, try your best to conform to the same coding style as in the rest of the source file you're editing.

Revision as of 16:38, 14 December 2012

If you're planning to submit pull requests for druntime or Phobos, you should follow the following coding conventions:

  • Style
    • Avoid using the tab character.
    • Use 4-space indentation.
    • Put a single splace between an if and it's corresponding parenthesis. Eg: if (condition)
    • For blocks enclosed by curly braces ({}), the opening and closing braces should be on their own lines, at the same indentation level as its containing block:
void main(string[] args)
{
    if (args.length == 0)
    {
        writeln("Please specify filename");
    }
    else
    {
        lotsOfDotDotDotMagic(args);
    }
}
  • Naming
    • Identifiers should use camelcase instead of underscores: myVariable instead of my_variable.
    • Types (or templates returning types) should use BumpyCase: ElementType instead of elementType or element_type.
  • Length of lines:
    • Lines should preferably not be longer than 80 characters, though this is a soft limit.
    • Documentation should never be longer than 80 characters. This is a hard limit.

Note that this are the guidelines. In general, just like in any collaborative project, try your best to conform to the same coding style as in the rest of the source file you're editing.