Commit 6f275f8a authored by Scott Wheeler's avatar Scott Wheeler

Add some notes on the coding style.

svn path=/trunk/kdemultimedia/juk/; revision=313338
parent 7a963038
Since I tend to be one of the more pedantic people on coding style I'll provide
a bit of a reference here. Please take a few minutes to read this as it will
save us both time when processing patches.
================================================================================
Indentation
================================================================================
The older files in JuK are indented using Qt-style. The first level was 4
spaces, the second one tab, the third one tab followed by 4 spaces. I'm not
particularly fond of this style anymore, but it used to be the Emacs default
when using the KDE Emacs scripts.
static void foo()
{
if(bar()) // <-- 4 spaces
baz() // <-- 1 tab
}
Newer files simply use 4 spaces at all levels. In most cases the style of the
file currently being worked in should be followed. So:
static void foo()
{
if(bar()) // <-- 4 spaces
baz() // <-- 1 tab
}
================================================================================
Braces
================================================================================
Braces opening classes, structs, namespaces and functions should be on their own
line. Braces opening conditionals should be on the same line with one notable
exception: if the conditional is split up onto several lines then the opening
brace should be on its own line. i.e.
class Foo
{
// stuff
};
if(foo == bar) {
// stuff
}
while(foo == bar &&
baz == quux &&
flop == pop)
{
// stuff
}
static void foo()
{
// stuff
}
Other exceptions include inline functions that are just returning or setting a
value. However multiple statements should not ever be combined onto one line:
class Foo
{
public:
String value() const { return m_value; }
};
Also conditionals / loops that only contiain one line in their body (but where
the conditional statement fits onto one line) should omit braces:
if(foo == bar)
baz();
But:
if(baz == quux &&
ralf == spot)
{
bar();
}
================================================================================
Spaces
================================================================================
Spaces should not be used between the conditional / loop type and the
conditional statement. They should also not be used after parenthesis. However
the should be to mark of mathematical or comparative operators.
if ( foo == bar )
^ ^ ^
The marked spaces should be ommitted to produce:
if(foo == bar)
================================================================================
Header Organization
================================================================================
Member variables should always be private and prefixed with "m_". Accessors may
be inline in the headers. The organization of the members in a class should be
roughly as follows:
public:
public slots:
protected:
protected slots:
signals:
private: // member funtions
private slots:
private: // member variables
If there are no private slots there is no need for two private sections, however
private functions and private variables should be clearly separated.
The implementations files -- .cpp files -- should follow (when possible) the
same order of function declarations as the header files.
Virtual functions should always be marked as such even in derrived classes where
it is not strictly necessary.
================================================================================
Whitespace
================================================================================
Whitespace should be used liberally. When blocks of code are logically distinct
I tend to put a blank line between them. This is difficult to explain
systematically but after looking a bit at the current code organization this
ideally will be somewhat clear.
Also I tend to separate comments by blank lines on both sides.
================================================================================
Pointer and Reference Operators
================================================================================
This one is pretty simple. I prefer "Foo *f" to "Foo* f" in function signatures
and declarations. The same goes for "Foo &f" over "Foo& f".
================================================================================
There are likely things missing here and I'll try to add them over time as I
notice things that are often missed. Please let me know if specific points are
ambiguous.
Scott Wheeler <wheeler@kde.org>
......@@ -89,21 +89,25 @@ void CollectionList::clear()
"Note, however, that if the directory that these files are in is in "
"your \"scan on startup\" list, they will be readded on startup."));
if(result == KMessageBox::Yes) {
// We're taking code from Playlist::clear() here.
PlaylistItemList l = selectedItems();
if (l.isEmpty())
l = items();
// We need to remove the items from the Cache. Rather
// ugly hack, unfortunately.
PlaylistItemList::Iterator it = l.begin();
for ( ; it != l.end(); ++it)
Cache::instance()->remove((*it)->file());
PlaylistItemList l = selectedItems();
if(l.isEmpty())
l = items();
// We need to remove the items from the Cache. Rather ugly hack,
// unfortunately.
// Now clear the items like normal
clearItems(l);
PlaylistItemList::Iterator it = l.begin();
for(; it != l.end(); ++it)
Cache::instance()->remove((*it)->file());
emit signalCollectionChanged();
// Now clear the items like normal.
clearItems(l);
emit signalCollectionChanged();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment