Coding style¶
The Qt coding style, with
.clang-format in the repository root as its written form:
Four spaces, never tabs; lines up to 100 characters.
Braces on their own line for classes, structs and function bodies, attached everywhere else (
if (x) {,} else {).*and&next to the name:Session *session,const QString &name.A space after control keywords, none after a function name:
if (ok),run(sql).Braces may be left out for single-statement bodies, but then the whole statement,
elsebranch included, goes without them.Names:
CamelCasetypes,camelCasefunctions and variables,m_for members,SCREAMING_CASEonly for macros.
Before committing:
clang-format -i $(git ls-files '*.cpp' '*.h')
Beyond the formatter¶
Comments say why, not what the next line already says. Where the reason is not obvious from the code, write a sentence; where it is, write nothing.
Every dialog’s layout lives in a Qt Designer
.uifile, so it can be changed without touching code.New behaviour comes with a test, and the test says what the behaviour is for rather than restating the implementation.
Logic stays out of the widgets. Only
src/appmay use Qt Widgets; what can be tested without a display belongs in a library.Nothing blocks the UI thread: work on a database goes through its session’s
sqlite::QueryRunner, as SQL or as a task.