Code style

From Apertium
Revision as of 10:25, 25 March 2016 by Frankier (talk | contribs)
Jump to navigation Jump to search

C++

Which features/libraries to prefer/Semantics

New code should prefer modern C++ using C++03. Here, modern C++ is defined in opposition to "C with classes" style. (Note, there is quite a bit of existing code which would probably qualify as "C with classes".) In practice, for our purposes, This means:

Do

  • Use const and references where possible
  • Prefer C++ casts over C casts
  • Prefer the C++ stdlib over the C standard library
  • Prefer usage of smart pointers over manual memory management when stack/global allocation don't do the trick.
  • Prefer containers over home made data structures.

Don't

  • Use void*
  • Use sprintf
  • If the pointer lifetime is the same as the object it refers to. Don't use a raw pointer.

Formatting/Syntax

This is less important. Currently through the code base there are:

  • Sergio's style
  • m5w's style
  • felipe's style

Most code is Segio's style.

Wiki TODO: Document this below.

Possible project TODO: Run clang-format

Names

...

Whitespace

...

Python

...