The practice of C++

Contents

  1. Source code
  2. Building
  3. Static Analysis
  4. Runtime Analysis
  5. Tests

Source Code

Coding Style

  • Choose one coding style and stick to it
  • Whenever necessary change it.

IDEs or text editors

Platform specific

  • Visual Studio
  • xcode
  • kdevelop

Cross-platform

  • qtcreator
  • Eclipse with CDT

New players

Basic Text settings

CONSISTENCY

that easy when working on multiple projects / codebases withstyles
  • [Editor Config](http://editorconfig.org/)

CodeMaid

CodeMaid is an open-source extension that allows code cleanup and reorganizing.

clang-format

  • portable, stand-alone tool
  • plugins for Vim, Emacs, Visual Studio, Git
  • uses clang+++ AST to reformat the code
  • allows to specify different formatting rules for different files

Building

  • C++ doesn't have build system

built-in in the IDE

  • Visual Studio project files
  • Xcode project files
  • qtcreator - qmake

standalone - low level

  • make - in all the ports and flavours
  • ninja

stanalone - high level

  • cmake - can generate everything
  • gyp
  • premake5 - Visual Studio, make, xcode soon
  • genie

Distributed

Libraries

Program configuration

Logging

Data Persistance

  • dropbox json11
  • boost::serialization

Testing

Microbenchmarking

Graphics

  • DirectX / OpenGL
  • SFML
  • SDL
  • cairo / Skia

GUI

  • Qt
  • WxWidgets
  • GTK
  • Win32
  • IUP
  • fltk

Text

  • boost::spirit
  • boost::karma
  • ctemplate

Image processing

  • lodepng

Scripting

  • Lua, luajit
  • duktape, v8
  • python - boost::python, cython

Networking

Static code analysis

Tries to run all possible code paths in the program in order to locate errors.

False positives

It may find so many "errors" that is impossible to check all of them.

void generate(int* output); // third party

std::unique_ptr<int[]> p(new int[1024]);

generate(p.get()); // reading uninitialized memory
std::cout << p[24]; // reading uninitialized memory

Visual Studio

  • Starting VS2013 in all versions

PVS-Studio

clang++ --analyze

Runs clang in static analyzer mode

  • scan-build

Runtime analysis

  • valgrind
  • address sanitizer

Debuggers

  • Visual Studio / xcode
  • ddd