Website Summary Files Commits Branches @commit @diff @stats
path: root / JSImpl / CodingStyle.md
diff options
context:
space:
mode:
Commitd628aafd3e0029f4cc4e3cbbeae0bd1fcd5a3356 (patch)
Author
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-10-10 00:20:00 +0300
Committer
 Dimitar Trendafilov <dimitar@coherent-labs.com>
2018-10-10 00:20:00 +0300
Files7f1e693bdc22a4dc059f6197c4820126a52f16a2 /JSImpl/CodingStyle.md
IPL-d628aafd3e0029f4cc4e3cbbeae0bd1fcd5a3356.tar
IPL-d628aafd3e0029f4cc4e3cbbeae0bd1fcd5a3356.tar.gz
IPL-d628aafd3e0029f4cc4e3cbbeae0bd1fcd5a3356.zip
Parent9f19b6021fe149a17816d7c52e451069afe36d52 (diff)
A bit formatting for the code style
1 files changed, 208 insertions, 155 deletions
-rw-r--r--JSImpl/CodingStyle.md363
diff --git a/JSImpl/CodingStyle.md b/JSImpl/CodingStyle.md
index d4182ca..9943911 100644
--- a/JSImpl/CodingStyle.md
+++ b/JSImpl/CodingStyle.md
@@ -1,199 +1,244 @@
-C++ coding style guide
+# C++ coding style guide
-Spacing
+## Spacing
+
Do not place spaces around unary operators.
Right:
-i++;
+
+ i++;
+
Wrong:
-i ++;
+
+ i ++;
+
Do place spaces around binary and ternary operators.
Right:
-y = m * x + b;
-f(a, b);
-c = a | b;
-return condition ? 1 : 0;
+
+ y = m * x + b;
+ f(a, b);
+ c = a | b;
+ return condition ? 1 : 0;
+
Wrong:
-y=m*x+b;
-f(a,b);
-c = a|b;
-return condition ? 1:0;
+
+ y=m*x+b;
+ f(a,b);
+ c = a|b;
+ return condition ? 1:0;
+
Place spaces around the colon in a range-based for loop.
Right:
-Vector<PluginModuleInfo> plugins;
-for (auto& plugin : plugins)
- registerPlugin(plugin);
+
+ Vector<PluginModuleInfo> plugins;
+ for (auto& plugin : plugins)
+ registerPlugin(plugin);
+
Wrong:
-Vector<PluginModuleInfo> plugins;
-for (auto& plugin: plugins)
- registerPlugin(plugin);
+
+ Vector<PluginModuleInfo> plugins;
+ for (auto& plugin: plugins)
+ registerPlugin(plugin);
+
Do not place spaces before comma and semicolon.
Right:
-for (int i = 0; i < 10; ++i)
- doSomething();
-f(a, b);
+ for (int i = 0; i < 10; ++i)
+ doSomething();
+
+ f(a, b);
+
Wrong:
-for (int i = 0 ; i < 10 ; ++i)
- doSomething();
-f(a , b) ;
+ for (int i = 0 ; i < 10 ; ++i)
+ doSomething();
+
+ f(a , b) ;
+
Place spaces between control statements and their parentheses.
Right:
-if (condition)
- doIt();
+
+ if (condition)
+ doIt();
+
Wrong:
-if(condition)
- doIt();
-Do not place spaces between a function and its parentheses, or between a parenthesis and its content.
+
+ if(condition)
+ doIt();
+
+Do not place spaces between a function and its parentheses, or between a
+parenthesis and its content.
Right:
-f(a, b);
+
+ f(a, b);
+
Wrong:
-f (a, b);
-f( a, b );
-When initializing an object, place a space before the leading brace as well as between the braces and their content.
+
+ f (a, b);
+ f( a, b );
+
+When initializing an object, place a space before the leading brace as well as
+between the braces and their content.
Right:
-Foo foo { bar };
+
+ Foo foo { bar };
+
Wrong:
-Foo foo{ bar };
-Foo foo {bar};
+ Foo foo{ bar };
+ Foo foo {bar};
+## Line breaking
-Line breaking
Each statement should get its own line.
Right:
-x++;
-y++;
-if (condition)
- doIt();
+
+ x++;
+ y++;
+ if (condition)
+ doIt();
+
Wrong:
-x++; y++;
-if (condition) doIt();
-An else statement should go on the next line as a preceding close brace if one is present.
+
+ x++; y++;
+ if (condition) doIt();
+
+An else statement should go on the next line as a preceding close brace if one
+is present.
Right:
-if (condition)
-{
- ...
-}
-else
-{
- ...
-}
-if (condition)
- doSomething();
-else
- doSomethingElse();
+ if (condition)
+ {
+ ...
+ }
+ else
+ {
+ ...
+ }
+
+ if (condition)
+ doSomething();
+ else
+ doSomethingElse();
+
+ if (condition)
+ doSomething();
+ else
+ {
+ ...
+ }
-if (condition)
- doSomething();
-else
-{
- ...
-}
Wrong:
-if (condition) {
- ...
-}
-else {
- ...
-}
+
+ if (condition) {
+ ...
+ }
+ else {
+ ...
+ }
+
-Braces
+## Braces
Place braces on the line after if/for/else/ function definition etc.
Right:
-int main()
-{
- ...
-}
-class MyClass
-{
- ...
-};
+ int main()
+ {
+ ...
+ }
-for (int i = 0; i < 10; ++i)
-{
- ...
-}
+ class MyClass
+ {
+ ...
+ };
+
+ for (int i = 0; i < 10; ++i)
+ {
+ ...
+ }
+
+ namespace WebCore
+ {
+ ...
+ }
-namespace WebCore
-{
- ...
-}
Wrong:
-int main() {
- ...
-}
+ int main() {
+ ...
+ }
-class MyClass {
- ...
-};
+ class MyClass {
+ ...
+ };
-for (int i = 0; i < 10; ++i) {
- ...
-}
+ for (int i = 0; i < 10; ++i) {
+ ...
+ }
-namespace WebCore {
- ...
-}
+ namespace WebCore {
+ ...
+ }
-One-line control clauses should not use braces unless comments are included or a single statement spans multiple lines.
+One-line control clauses should not use braces unless comments are included or a
+single statement spans multiple lines.
-Names
+## Names
-Use CamelCase. Capitalize the first letter, including all letters in an acronym, in a class, function, struct, protocol, or namespace name.
-Lower-case the first letter, including all letters in a local variable.
-Use prefix 'm_' for class members and CamelCase without prefix for struct members.
-Use CamelCase for static class and struct members.
+Use CamelCase. Capitalize the first letter, including all letters in an acronym,
+in a class, function, struct, protocol, or namespace name. Lower-case the first
+letter, including all letters in a local variable. Use prefix 'm_' for class
+members and CamelCase without prefix for struct members. Use CamelCase for
+static class and struct members.
Right:
-struct Data;
-size_t bufferSize;
-class HTMLDocument;
-String mimeType();
-class A
-{
- ...
- int m_Count;
-}
+ struct Data;
+ size_t bufferSize;
+ class HTMLDocument;
+ String mimeType();
+
+ class A
+ {
+ ...
+ int m_Count;
+ }
+
+ struct A
+ {
+ ...
+ int m_Count;
+ }
-struct A
-{
- ...
- int m_Count;
-}
Wrong:
-struct data;
-size_t buffer_size;
-class HtmlDocument;
-String MIMEType();
-class A
-{
- ...
- int count;
-}
+ struct data;
+ size_t buffer_size;
+ class HtmlDocument;
+ String MIMEType();
+
+ class A
+ {
+ ...
+ int count;
+ }
-struct A
-{
- ...
- int Count;
-}
+ struct A
+ {
+ ...
+ int Count;
+ }
Data members in C++ classes should be private.
@@ -201,43 +246,51 @@ Data members in C++ classes should be private.
Precede boolean values with words like “is” and “did”.
Right:
-bool isValid;
-bool didSendData;
+
+ bool isValid;
+ bool didSendData;
+
Wrong:
-bool valid;
-bool sentData;
-Constructors for C++ classes should initialize all of their members using C++ initializer syntax. Each member (and superclass) should be indented on a separate line, with the colon or comma preceding the member on that line.
+ bool valid;
+ bool sentData;
+
+Constructors for C++ classes should initialize all of their members using C++
+initializer syntax. Each member (and superclass) should be indented on a
+separate line, with the colon or comma preceding the member on that line.
Right:
-MyClass::MyClass(Document* document)
- : MySuperClass()
- , m_myMember(0)
- , m_document(document)
-{
-}
-MyOtherClass::MyOtherClass()
- : MySuperClass()
-{
-}
+ MyClass::MyClass(Document* document)
+ : MySuperClass()
+ , m_myMember(0)
+ , m_document(document)
+ {
+ }
+
+ MyOtherClass::MyOtherClass()
+ : MySuperClass()
+ {
+ }
+
Wrong:
-MyClass::MyClass(Document* document) : MySuperClass()
-{
- m_myMember = 0;
- m_document = document;
-}
-MyOtherClass::MyOtherClass() : MySuperClass() {}
+ MyClass::MyClass(Document* document) : MySuperClass()
+ {
+ m_myMember = 0;
+ m_document = document;
+ }
+
+ MyOtherClass::MyOtherClass() : MySuperClass() {}
-Using namespace - do not use “using” never!
+## Using namespace - do not use `using` never!
-Pointers and memory managment
+## Pointers and memory managment
Use smart pointers always for example IPLSharedPtr.
Never use raw new. You can use IPLMakeSharePtr instead.
-Containers
+## Containers
You can use everything from CommonTypes.h for example IPLVector,
IPLString, IPLUnorderedMap if you need something more think twice