Difference between revisions of "Projects/KDevelop4/CodingStyle"

Jump to: navigation, search
 
Line 2: Line 2:
  
 
For new files / projects / plugins, please use the [[Policies/Kdelibs_Coding_Style]] guidelines. Here are a few special additions:
 
For new files / projects / plugins, please use the [[Policies/Kdelibs_Coding_Style]] guidelines. Here are a few special additions:
 +
 +
== QObject and Access Modifiers ==
 +
 +
<syntaxhighlight lang="cpp-qt">
 +
// wrong
 +
class Foo : public QObject {
 +
Q_OBJECT
 +
  public:
 +
    Foo();
 +
  private:
 +
    int bla;
 +
};
 +
 +
// correct foo.h
 +
class Foo: public QObject
 +
{
 +
    Q_OBJECT
 +
public:
 +
    Foo();
 +
private:
 +
    int m_bla;
 +
};
 +
</syntaxhighlight>
  
 
== Class Initialization ==
 
== Class Initialization ==
Line 9: Line 32:
 
class Foo : public Bar {
 
class Foo : public Bar {
 
public:
 
public:
  Foo(int i, int j) : Bar(i), bla(j) {}
+
    Foo(int i, int j) : Bar(i), bla(j) { /* do stuff */ }
 
private:
 
private:
  int bla;
+
    int bla;
 
};
 
};
  
Line 18: Line 41:
 
{
 
{
 
public:
 
public:
  Foo(int i, int j);
+
    Foo(int i, int j);
 
private:
 
private:
  int m_bla;
+
    int m_bla;
 
};
 
};
 
// foo.cpp
 
// foo.cpp
Line 27: Line 50:
 
, m_bla(j)
 
, m_bla(j)
 
{
 
{
 +
    // do stuff
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 32: Line 56:
 
== Using Namespaces ==
 
== Using Namespaces ==
  
Never add a "using namespace ..." to a header. Do use that though in every .cpp file , esp. for the KDevelop namespace.
+
Never add a "using namespace ..." to a header. Do use that though in every .cpp file , esp. for the KDevelop namespace. Public API should always be in the KDevelop namespace.

Latest revision as of 23:08, 11 November 2012

The current KDevelop code base is very inconsistent when it comes to the coding style. So please adhere to the file's coding style you are working on / patching.

For new files / projects / plugins, please use the Policies/Kdelibs_Coding_Style guidelines. Here are a few special additions:

[edit] QObject and Access Modifiers

// wrong
class Foo : public QObject {
Q_OBJECT
  public:
    Foo();
  private:
    int bla;
};
 
// correct foo.h
class Foo: public QObject
{
    Q_OBJECT
public:
    Foo();
private:
    int m_bla;
};

[edit] Class Initialization

// wrong foo.h
class Foo : public Bar {
public:
    Foo(int i, int j) : Bar(i), bla(j) { /* do stuff */ }
private:
    int bla;
};
 
// correct foo.h
class Foo: public Bar
{
public:
    Foo(int i, int j);
private:
    int m_bla;
};
// foo.cpp
Foo::Foo(int i, int j)
: Bar(i)
, m_bla(j)
{
    // do stuff
}

[edit] Using Namespaces

Never add a "using namespace ..." to a header. Do use that though in every .cpp file , esp. for the KDevelop namespace. Public API should always be in the KDevelop namespace.


This page was last modified on 11 November 2012, at 23:08. This page has been accessed 1,763 times. Content is available under Creative Commons License SA 3.0 as well as the GNU Free Documentation License 1.2.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V.Legal