Skip to content

Code style

Ihar Hubchyk edited this page Jan 28, 2021 · 6 revisions

Each pull request goes through code style formatting check (Static Analysis job in GitHub Actions) to make sure that suggested code is up to our coding standards. In any case we don't strictly enforce to follow coding rules in some situations :)

We use Clang format coding style. Please refer to clang-format file for more information.

Not every code style check could be performed by the above described tool. This is a description covering the rest of coding standard. Please note that project's code base contains a lot of old code which is not followed by this standard:

Naming

  • classes and structures are named in CamelCase style.
  • members of structures must be named in camelCase starting from lower character.
  • members of class must be named in _camelCase starting from '_' following by a lower character.
  • public methods must be named in camelCase starting from lower character.
  • protected and private methods must be named in _camelCase starting from '_' following by a lower character.
  • global and static functions and variables are named in camelCase starting from lower character. All variables and functions outside classes and structures must be put within a namespace.
namespace
{
    const std::string planetName("Earth");

    bool isCodeTrusted()
    {
        return true;
    }
}

class BlackMarket
{
public:
    BlackMarket();

    ~BlackMarket();

    bool isOpen() const;

private:
    size_t _availableTraders;

    void _precalculateRatio();
};

struct Phone
{
    uint64_t price;

    bool secondHand;
};