From 8116837afad562c3c1b52358ed6fc9a2267e1ea6 Mon Sep 17 00:00:00 2001 From: Martin Polanka Date: Fri, 11 Dec 2015 11:23:05 +0100 Subject: [PATCH] Created Coding style (markdown) --- Coding-style.md | 105 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Coding-style.md diff --git a/Coding-style.md b/Coding-style.md new file mode 100644 index 0000000..44ff624 --- /dev/null +++ b/Coding-style.md @@ -0,0 +1,105 @@ +# Coding style + +Every project should have some consistent coding style in which all contributors write. Bellow you can find our conventions on which we agreed on and which we try to keep. + +## C++ + +In C++ is written worker and queue manager. Generally its used underscore style with all small letters. Inspired by [Google C++ style guide](https://google.github.io/styleguide/cppguide.html) + +### Naming convention +* For source codes use all lower case with underscores not dashes. Header files should end with `.h` and C++ files with `.cpp`. +* Typenames are all in lower case with underscores between words. This is applicable to classes, structs, typedefs, enums and type template parameters. +* Variable names can be divided on local variables and class members. Local variables are all lower case with underscores between words. Class members have in addition trailing underscore on the end (struct data members do not have underscore on the end). +* Constants? +* All function names are again all lower case with underscores between words. +* Namespaces if there are ones they should have lower case and underscores. +* Macros are classical and should have all capitals and underscores. +* Comments can be two types documentational and ordinery ones in code. Documentation should start with `/**` and end with `*/`, convention between this is javadoc documentation format. Classical comments in code starts with `?` and end with `?`. (NOT DECIDED YET) + +### Formatting convention +* Line length 80 characters. (NOT DECIDED YET) +* All files should use UTF-8 character set. +* For code indentation tabs (`\t`) are used. +* Function declaration/definition: return type should be on the same line as the rest of the declaration, if line is too long, than particular parameters are placed on new line. Opening parenthesis of function should be placed on new line bellow declaration. Its possible to write small function which can be on only one line. Between parameter and comma should be one space. +``` +int run(int id, string msg); + +void print_hello_world() +{ + std::cout << "Hello world" << std::endl; + return; +} + +int get_five() { return 5; } +``` +* Lambda expressions: same formatting as classical functions +``` +auto hello = [](int x) { std::cout << "hello_" << x << std::endl; } +``` +* Function calls: basically same as function header definition. +* Condition: after if, or else there always have to be one space in front of opening bracket and again one space after closing condition bracket (and in front of opening parenthesis). If and else always should be on separate lines. Inside condition there should not be any pointless spaces. +``` +if (x == 5) { + std::cout << "Exactly five!" << std::endl; +} else if (x < 5 && y > 5) { + std::cout << "Whoa, that is weird format!" << std::endl; +} else { + std::cout << "I dont know what is this!" << std::endl; +} +``` +* For and while cycles: basically same rules as for if condition. +* Switch: again basics are the same as for if condition. Case statements should be indented with tab and case body with 2 tabs. +``` +switch (switched) { + case 0: // tab indent + ... // 2 tabs indent + break; + case 1: + ... + break; + default: + exit(1); +} +``` +* Pointers and references: no spaces between period or arrow in accessing type member. No spaces after asterisk or ampersand. In declaration of pointer or reference format should be that asterisk or ampersand is adjacent to name of the variable not type. +``` +number = *ptr; +ptr = &val; +number = ptr->number; +number = val_ref.number; + +int *i; +int &j; + +// bad format bellow +int* i; +int * i; +``` +* Boolean expression: long boolean expression should be divided into more lines. The division point should always be after logical operators. +``` +if (i > 10 && + j < 10 && + k > 20) { + std::cout << "Were here!" << std::endl; +} +``` +* Return values should not be generally wrapped with parentheses, only if needed. +* Preprocessor directives start with `#` and always should start at the beginning of the line. +* Classes: sections aka. public, protected, private should have same indentation as the class start itself. Opening parenthesis of class should be on the new line. +``` +class my_class +{ +public: + void class_function(); +private: + int class_member_; +} +``` +* Operators: around all binary operators there always should be one space. +``` +int x = 5; +x = x * 5 / 5; +x = x + 5 * (10 - 5); +``` + +## PHP \ No newline at end of file