Community / Community and Contributions

Code Style Guide

C++ formatting and naming conventions for contributions to the Trace app, which follow KiCad's style.

The Trace app's C++ code follows KiCad's style. This page sums up the rules. Before you start on a change, read Contributing.

Formatting

The repository's _clang-format file sets the formatting. Run clang-format on the lines you changed, not on whole files. Where clang-format and the surrounding code disagree, match the surrounding code.

The main rules:

  • Four spaces per indent, no tabs.
  • Eight spaces for continuation lines and constructor initializer lists.
  • Lines up to 120 characters.
  • Braces on their own lines (Allman style).
  • Spaces inside non-empty parentheses, and no space before them: Foo( aValue ).
  • * and & attached to the type: int* aCount.
  • Include order is left as written.
  • The body of an if, for or while goes on its own line, never on the condition's line. A one-line body may go without braces; follow the surrounding code.
class VALUE_HOLDER
{
public:
    void SetValue( int aValue )
    {
        m_value = aValue;
    }

private:
    int m_value = 0;
};

Naming

  • Classes: UPPER_SNAKE_CASE, such as BOARD_ITEM.
  • Methods: PascalCase, such as GetPosition().
  • Member variables: an m_ prefix, such as m_value.
  • Parameters: an a prefix, such as aValue.

Don't rename existing code just to match these rules.

Comments

Explain why, not what: note assumptions, edge cases and anything surprising. Document public functions, including who owns returned objects and what return values mean. Keep existing copyright and licence headers.

Testing

Build what you changed, test both the normal path and the failure path, and say in your pull request which platforms you tested on.

For upstream background, see the KiCad Code Style Policy.