Skip to content

Robomongo Coding Style

schetnikovich edited this page Jan 10, 2013 · 41 revisions

In most cases we follow MongoDB style guides, which in turns tries to follow Google C++ Style Guide.

The most notable Robomongo rules are:

#includes

Use "double quotes" for Robomongo code, <angle brackets> for 3rd party or library headers, including MongoDB files:

#include <QStringList>
#include <boost/shared_ptr.hpp>
#include <mongo/client/dbclient.h>

#include "robomongo/core/Core.h"
#include "robomongo/core/MongoElement.h"

All of a project's header files should be listed as descendants of the project's src/ source directory without use of directory shortcuts (. and ..).

Correct:

#include "robomongo/core/MongoElement.h"

Wrong:

#include "core/MongoElement.h"
#include "../core/MongoElement.h"
#include "MongoElement.h"

Header (.h) files

Follow this order:

  1. #pragma once at the top. Blank line.
  2. Third party #includes, sorted. Blank line.
  3. Robomongo #includes, sorted. Blank line.

Implementation (.cpp) files

  1. Primary file #include, if applicable. Blank line.
  2. Third party #includes, sorted. Blank line.
  3. Robomongo #includes, sorted. Blank line.

Declaration Order

Your class declaration should be divided on 'access' sections in the following order:

  1. public:
  2. signals:
  3. public slots:
  4. protected:
  5. protected slots:
  6. private:
  7. private slots:

If any of these sections are empty, omit them.

Within each section, the declaration should be in the following order:

  1. Typedefs and Enums
  2. Constants (static const data members)
  3. Constructors
  4. Destructor
  5. Methods, including static methods
  6. Data members

Method definitions in the corresponding .cpp file should be the same as the declaration order.

Do not put large method definitions inline in the class definition. Usually, only trivial or performance-critical, and very short, methods may be defined inline.

Clone this wiki locally