Main  /  Edit  /  History  /   /  Users Area

CppCMS Coding Standard

Coding Style

General Coding Notes


All code you write should be exception safe. Only functions that you may assume they never throw exceptions are POSIX API or 3rd party C libraries like libgcrypy or sqlite3. Even STL may throw exception. Assume that std::bad_alloc may be thrown and handle it correctly.



CppCMS uses Boost libraries heavily, however it does not use Boost.Threads, it use POSIX threads


  1. Pthread are better documented.
  2. Boost.Threads are "GCD" of Win32 thread API and Posix threads and do not provide important features like: process shared mutex.
  3. There are several backward incompatible changes within Boost.Threads and some bugs in versions of Boost that CppCMS supports.

Other Notes:


Do not reinvent the wheel, use STL --- it is well document, well known, highly available library that does the job. Use it.


  1. Always prefer std::vector to std::list --- it has better performance because it is cache friendly.
  2. Always prefer std:string for text storage.
  3. It is OK to return STL collections from functions, compiler know how to optimize them.
  4. Do not forget swap() function --- it can save lot's of unnecessary copies for you. For example:

     string foo();
     void bar() 
        string s;
        for(;;) {
          // Not s=foo();

    Description: when you call s=foo() assignment operator is called that copies the value that foo() returned to s and then releases it. When you call s.swap(foo()) the value in s is replaced by returned value and the old value in s is cleaned --- you saved copy of probably huge buffer, you operation is done in O(1).

  5. If you have non-copyable class, you can store it in STL collection using shared_ptr.



CppCMS should work with at least Boost 1.33.1. Thus, if you use more modern features, provide autoconf macros and use conditional builds. For example, Boost.Asio that had been introduced in Boost 1.35.

Generally prefer boost over other libraries, however use Boost features carefully, or do not use at all. Examples:

  1. Boost Interprocess too "heavy" and little bit "ugly" because it supports windows and supports placing any objects in memory. The nature of fork() gives much better functionality and allows placing any object in shared memory every time it use shared memory allocators.
  2. Boost Threads -- see notes above.
  3. Boost Serialization -- has too many performance overheads .


  1. All libraries should be OpenSource libraries
  2. Prefer non-copyleft licenses like MIT, 3 clause BSD, Boost over copyleft one, like LGPL.
  3. All libraries, CppCMS uses should be compatible with LGPLv2. Unless:

    • It is 4 clause BSD license
    • There is no other libraries that may provide similar functionality.

    For example:

    • There is no alternatives for libmm, it is licensed under 4 clause BSD -- it may be used with exception notes for LGPL license of CppCMS that allows linking with 4 clause BSD.
    • OpenSSL --- no, there is an alternative libgcrypt
    • Qt4 --- no, it has strong Copyleft semantics not compatible with LGPL.
  4. You may use strong copyleft libraries for stand alone utilities that are not linked with CppCMS framework.

    For example: If you want to write GUI for cppcms_tcp_scale utility using Qt you are welcome.


If you want to add an additional dependency for CppCMS make sure:

  1. There is a big value for adding such dependency.
  2. This library is highly available.
  3. You checked all alternatives and decided that this one is the best.
  4. You had added an autoconf macro and conditional build for CppCMS that allows building all framework without this library.

For example, libgcrypt:


CppCMS is a web development framework for performance demanding applications.

Support This Project Logo

Поддержать проект

CppCMS needs You


Main Page

Valid CSS | Valid XHTML 1.0