allow_warnings = 0
in the SCons
build configuration.Add a comment with copyright information to every file you add to the project. The copyright should be of the following form:
/*
* Copyright (c) 2012-2013 John Doe
* Licensed under the Simplified BSD license.
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
myThing
, myJIDFactory
, …MyClass
, MyJIDFactory
getValue
, setValue
.
For boolean tests, use is
as prefix, e.g. isValid()
myVariable
._
to the
end of member variable names, which is ok (but not required). When editing a class, use the same
convention as the rest of the member variables.MY_MACRO
, static const int MY_CONSTANT
.cpp
(C++), .m
(Objective-C), .mm
(Objective-C++); header
files have the extension .h
.Always use braces for control statements, even if the body only contains one statement. E.g.
if (foo) {
bar();
}
NOT
if (foo)
bar();
Namespace indentation: in .cpp
files, don’t indent code inside the main namespace
E.g.
namespace Swift {
JID::JID() {
...
}
}
This avoids needless indentation. What also usually works is:
using namespace Swift;
JID::JID() {
...
}
For anonymous namespaces, it is ok to indent as usual:
namespace {
struct Foo {
};
}
Put the *
with the type. E.g.
Foo* myFoo;
NOT:
Foo *myFoo;
#include <...>
(so not #include "..."
)iostream
Swiften/Base/Log.h
Swiften/Base/foreach.h
.cpp
file, always include the header of the file you’re declaring first. This avoids accidental
hidden dependencies that aren’t included in the header.Swiften/Parser/ExpatParser.h
Always use SWIFTEN_OVERRIDE
(Swiften/Base/Override.h
) when overriding virtual methods, e.g.
virtual bool myOverriddenMethod() const SWIFTEN_OVERRIDE
Always use SWIFTEN_API
(Swiften/Base/API.h
) on Swiften classes, except for classes that need to
remain private
using namespace
in headers. This pollutes the global namespace of every site that
includes your header.default
case statements when switching on an enum
. This makes sure that we get
compiler warnings whenever a value is added to an enum
..cpp
file ensures this.
(Note: not all classes currently adhere to this rule yet).++i
) over post-increment (i++
). Post-increment can have a performance hit.vector<>
over list<>
. Even when regularly inserting or removing from random places in
a container, vector
outperforms list
(for data types that aren’t too large)assert
often. Don’t forget to include <cassert>
if you use assert
.const
.
If you want to break this rule, please ask us first before submitting
the patch.