Skip to content

CodingStyle

Alexander Barthel edited this page Nov 17, 2018 · 2 revisions

Coding Style

If you're in Rome do it like the Romans.

You can use the included uncrustify.cfg and Uncrustify to format the code. Avoid formatting whole files since this can result in merge conflicts.

General

  • Do not use Hungarian Notation.
  • Do not prefix class variables with underscore _.
  • Class, struct and enum names in camel case with first letter upper case: MapProcedureLegs. No underscores.
  • Variable and parameter names in camel case with first letter lower case: currentDistanceMarkerIndex. No underscores.
  • Constants and enum values all upper case with underscores: MAX_SIM_UPDATE_TOOLTIP_MS.
  • Use get and set prefixes for simple setters and getters.
  • File names shall correspond to class names if applicable. Use only lower case, .h and *.cpp file endings.
  • Sub directories in source tree all lower case.
  • Mind the case in includes. This has to compile on Linux too.
  • Always use const references when passing bigger structures to methods. Do this also for the inherently shared classes like QString.

Qt

  • Use QString and other Qt container classes instead of std::string or std::vector.
  • Do not use the old SIGNAL and SLOT macros. These are not type safe: QObject::connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int)));. Use the new methods instead: QObject::connect(&a, &Counter::valueChanged, &b, &Counter::setValue);
Clone this wiki locally