Naming conventions



#include order



  1. If it’s implementation file, the corresponding header file.
  2. Standard C++/STL headers like iostream or functional. Prefer C++ headers (say, cmath) over C-style ones (math.h).
  3. Boost headers.
  4. Qt headers.
  5. Any other library headers.
  6. LeechCraft headers.
  7. Your own files.

Variable declarations, function declarations and general things



Identation and line breaks



Whitespaces



Examples



So, an example header file would be like:

#pragma once

#include 

namespace LeechCraft
{
struct Entity;

namespace YourCode
{
    class SomeClass : public QObject
    {
        Q_OBJECT
    public:
        SomeClass (QObject* = 0);

        int Get42 () const;
    public slots:
        void handle42Changed (int);
    signals:
        void gotEntity (const LeechCraft::Entity&);
    }
}
}



The corresponding source file would be:

#include "someclass.h"
#include 
#include 
#include 
#include 
#include 
#include "core.h"

namespace LeechCraft
{
namespace YourCode
{
    namespace
    {
        int func (int a, MyClass *f)
        {
            int result = f->GetID () +
                    SomeAnotherLongFunctionYouWillDefinitelyWantToWrap (a);
            result *= Core::Instance ().GetSomeCalculator ()->
                    Initialize ().GetFactor ();
            result /= Core::Instance ()
                    .AnotherReaaaallyLongFunction (result, a);
            if ((result == 42 &&
                        !a) ||
                    a == 42)
                std::cout << "Truth is out there" << std::endl;
            return result;
        }
    }

    SomeClass::SomeClass (QObject *parent)
    : QObject (parent)
    {
    }

    int SomeClass::Get42 ()
    {
        return 42;
    }

    void SomeClass::handle42Changed (int newNum)
    {
        if (newNum != 42)
            throw std::runtime_error ("WTF? 42 isn't 42!");

        emit gotEntity (Entity ());
    }
}
}

Language



Example IDE settings



KDevelop is the IDE of choice for LeechCraft. It’s a sophisticated IDE, supporting CMake projects, having awesome autocomplete features that can even handle Boost-rich code, and KDevelop 4.3 would also support features like lambdas, autos and variadic templates from C++11 when released.

The following settings make autoformatting the most close the LC’s codestyle.

First, we make a custom codestyle in KDevelop’s settings: Custom code style Please note the Add Kate Modeline checkbox on this screenshot.

The custom style’s settings should be something like this: Custom code style settings Custom code style settings