Skip to content
svenstaro edited this page Mar 12, 2012 · 28 revisions

http://wiki.qt-project.org/Coding_Style

Format

  • Line limit: 100 characters
  • Private Functions: _likeThis()
  • Functions: likeThis()
  • Members: mLikeThis
  • Macros, enum values and globals: LIKE_THIS
  • Local objects, Parameters: like_this
  • Pointers: Like* this
  • References: Like& this
  • Use 4 real spaces per level of indentation
  • Comparisons: if("stuff" == "stuff")
  • Use braces ({}) for one-line blocks

Blocks:

while(true) {
    DoStuff();
}

Guideline

  • The code needs to compile without warnings as they are treated as errors.
  • Use the stack whenever possible. If a single dynamic allocation is required, use std::shared_ptr. For multiple dynamic allocations, be sure to put them into a boost::ptr_container.
  • Do not use copy constructors unless required! Good: std::string blah("hi"), bad: std::string blah = "hi"
  • Run valgrind on your stuff. Make sure it comes out clean.
  • Document every bit of code using doxygen.
  • Practice const-correctness.
  • Never commit stuff that doesn't compile or that breaks tests.
  • Don't use the using keyword. We like our code to be explicit since we are working with so many different libraries and otherwise the function origins wouldn't always be clear.
  • Add license headers to your files. See other file in the project to see what they look like.
  • Use initializer lists where possible.
  • Always use concrete int types like uint16_t from <cstdint>. This ensures that everything is cross-architecture compatible.
  • Prefer the smallest types for your primitives as this is more efficient and it signals intent to programmers. Also make integers unsigned when they are not meant to be able to become negative.
  • Use the % operator when concatenating strings.
  • Includes:
    • own header in cpp
    • all includes required in HPP to .hpp, ordered 1. Config.hpp 1. Own Project 1. Externals 1. STL
    • all includes not required in HPP to .cpp, ordered as above
    • use forward-declarations when needed, but try to avoid them
Clone this wiki locally