Skip to content

2.4 Coding style

Phil Duby edited this page Apr 14, 2020 · 7 revisions

In general, try to stick with the style you find in existing files. Fritzing follows the Qt Coding style in most cases, but there are some differences.

Whitespace

The Fritzing source code has a mix of 4-spaces and tabs. To render properly, set your tab width to 4. For example, to set the tab width in git diffs: git config --global core.pager 'less -x1,5'

Preferably configure your editor to use tabs for C++ code, but do not reformat whole files.

Curly braces

Use curly braces for single line if or for statements. For example

    if ( condition ) {
        if ( other ) {
            a += 1;
        }
    }

This is not in line with qt style, but we think it is important to distinguish from

    if ( condition ) a = 1;
        if ( other )
            a += 1;

Especially since we have a mix of 4 spaces and tabs.

Line width is 120

It is ok to occasionally use 120 columns before breaking a line, so you are not forced to split calls like varWithToLongName->callToMethodWithAnotherLongName(justThisParameter, andAnotherOne)

This is not an invitation to create deeply nested conditional clauses!

Qt coding style

For everything else, please see Qt Coding Style and Qt Coding Conventions

If in doubt, don't hesitate to ask.