forked from thesentinelproject/threatwiki_node
-
Notifications
You must be signed in to change notification settings - Fork 0
Coding Conventions
abhishekbh edited this page May 20, 2012
·
1 revision
-
DO NOT USE TABS. Set your editor to use spaces instead
-
Use two spaces per indentation level
-
Use K&R Variant: 1TBS style indentation with same line braces on method and class openings (http://en.wikipedia.org/wiki/Indent_style#K.26R_style)
-
Either add a comment to empty scopes, or close them immediately after the opening
-
Key Examples:
// while commenting, leave a space between the slashes and the comment int main(int argc, char *argv[]) { // note the lack of space between main and the following brace // note the lack of space between brace and internal item // note the space after a comma inside the braces // note the space between the closing brace and the opening curly bracket while (x == y) { something(); // note the lack of space between method name and braces // add one empty line before a conditional statement or loop if (x < 0) { // note the spacing puts("Negative"); negative(x); } else if { // add braces even if condition is single lined puts("Non-negative"); // note the spacing } else { // to do } } finalthing(); }
-
Add your name to any file you create in the very first line in the following format
Copyright (C) 2011, First Last <[email protected]>
-
Leave a space after your name and then use opening PHP tag
-
Do not tab or add spaces before a class name
-
DO NOT close PHP tag at the end of a file
- Try to use single word class names
- Do not use underscores
- Begin new words with uppercases
- For any class that will be called in a lower-bound hierarchy, set visibility to Protected
- For any class that will be called inside a module, set visibility of Private
- Limit comments to as few words as possible
- Only add comments that describe a function
- Use descriptive names
- Do not use single character names such as 'i' or 'n';
- Do not use names that could be used again in the same scope, like 'num' or 'name'
- Do not begin variable names with an underscore
- Use underscores to separate multiple words, NOT camel casing
- Do not use variable names that could apply to the whole class
-
add the letter 'i' in small case before any parameter to represent 'incoming'
int myFunction(int iId, string iName) {}
- Do not use upper case to begin function names
- Use upper case to start new words in function names, NOT underscores