Open main menu

Difference between revisions of "Code Formatting Conventions"

→‎Vertical space: -- new section
(→‎Preprocessor pragmas: -- added section)
(→‎Vertical space: -- new section)
Line 183: Line 183:
}
}
</syntaxhighlight>
</syntaxhighlight>
* Note comment on whether fall through is intentional. Use exactly this and not some variation both for consistency and so that the compiler will see it and suppress potential warnings.
* Note the comment on whether fall through is intentional. Use exactly this and not some variation both for consistency and so that the compiler will see it and suppress potential warnings.


== Vertical space ==
'''Avoid composite one liners'''
<syntaxhighlight lang="cpp">
if (condition) do_foo();  // <-- bad example
// Proper way of writing it
if (condition)
    do_foo();
</syntaxhighlight>
'''Split out variable declarations'''
<syntaxhighlight lang="cpp">
int a = 1;
int b = 2;
int c;
c = a + b;
</syntaxhighlight>
'''Split out logical program blocks'''
<syntaxhighlight lang="cpp">
void MacWindowManager::setScreen(ManagedSurface *screen) {
    _screen = screen;
    delete _screenCopy;
    _screenCopy = nullptr;
    if (_desktop)
        _desktop->free();
    else
        _desktop = new ManagedSurface();
    _desktop->create(_screen->w, _screen->h, _pixelformat);
    drawDesktop();
}
</syntaxhighlight>


== Preprocessor pragmas ==
== Preprocessor pragmas ==