Clone
2
C/C++ Coding Conventions
Бычков Андрей edited this page 2023-06-16 18:00:36 +03:00

Вот некоторые соглашения которые сейчас используются и должны использоваться дальше в нашем коде:

1. We use include guards instead of #pragma once

2. 3rd-party headers must be included using <>, and our files - using ""

3. Author information, like "Created by John Doe on xx.xx.xxxx", which is inserted automatically by many IDEs when creating a new file, is not allowed and must be removed

4. General naming conventions examples:

Entity Example
Function doSomething
Local variable my_variable
Public data member my_member
Class MyClass
Template parameter Type,T,C,T1,T2,...
Constant (including static const members of a class) MyConstant
Member of enum MyEnumMember
Namespace MyNamespace
Property accessors example
Setter setFoo
Getter foo
Boolean getters canFoo, hasFoo, isFoo, ...

5. For asynchronous functions use suffix "Async", e.g: void loadAsync()

6. Avoid using [&] or [=] as lambda captions. It often causes problems with dangling references.

7. Put bodies of selection and iteration statements into compound blocks, even if the body is a one-liner E.g.:

    // Bad
    if (x)
        doSomething();

    // Good
    if (x)
    {
        doSomething();
    }