On 07/26/11 10:01, Thomas Gahr wrote:
> I thought it would be nice to have a wiki-page on redmine regarding coding-
> style since you are obviously on the verge of using a new style and I am 
> trying to find out how it exactly looks. So I would ask just one favour from 
> you and I will send you the source of a redmine-wiki page you only need to 
> copy&paste then. This way other users can benefit from it, too.
> 
> The favour: Could you re-format the following code-snippets according to your 
> style? And maybe add a few if you think I forgot something?

That's an excellent idea, thanks a lot. Attached Sample.cpp and
Sample.h. I believe that it matches Qt's coding style pretty closely.

The preferred indenting is four spaces, no tabs, and 120-130 characters
per line.

I'm still not sure what's the "real" convention for private members,
whether _foo, m_foo or foo_. Trojita already uses m_foo and _foo, I believe.

And finally, the Qt's rule about being able to break the rules looks
promising :).

Cheers,
Jan

-- 
Trojita, a fast e-mail client -- http://trojita.flaska.net/
/* Copyright (C) 2006 - 2011 Your Name <[email protected]>

   This file is part of the Trojita Qt IMAP e-mail client,
   http://trojita.flaska.net/

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or the version 3 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#include <QtClassA>
#include <QtClassB>

#include "Sample.h"
#include "AnotherClass.h"
#include "BClass.h"

namespace Gui {

A::A() : B(0), _privateIntMember(0), _privateDoubleMember(0)
{
}

A::A(SomeThing *arg) : 
    B(arg), _privateIntMember(0), _privateDoubleMember(0)
{
}

A::A(int a, int b) :
    B(0), _privateIntMember(0), _privateDoubleMember(0)
{
}

void A::someFunc() const
{
    // curly braces for one-liners?
    if (somethingIsWrong()) {
        doFoo();
    } else {
        doBar();
    }
    // I actually like Qt's rule that trivial blocks can be made compact:
    if (foo)
        return;

    // more code here
}

void A::someFunc(bool a, int b)
{
    // spaces inside between a and the brackets?
    if (a) {
        doFoo();
    } else {
        doBar();
    }

    // indent break along with the statements?
    switch (b) {
    case 0:
        zero();
        break;
    case 1:
        one();
        break;
    case 2:
        {
            notOne();
            notZero();
        }
        break;
    default:
        atLeastZero();
    }
}

} // namespace NameSpace
// Feel free to explicitly add a comment about the end of a namespace. I don't think it's that much useful, though.
// vim: :set textwidth=120

namespace NameSpace {

void A::booyaaahhh()
{
    // mind the spaces and the endl :)
    std::cout << "Booyaaahhh!" << std::endl;
}

}
/* Copyright (C) 2006 - 2011 Your Name <[email protected]>

   This file is part of the Trojita Qt IMAP e-mail client,
   http://trojita.flaska.net/

   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or the version 3 of the License.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef GUI_A_H
// try to include a namespace name in the include guard to prevent stuff like UTIL_H

#include <AHeader> // sort alphabetically
#include <BHeader>

class AHelperForwardDeclared; // sort alphabetically, too
class BHelperForwardDeclared;
class CHelperForwardDeclared;

namespace Gui {

class A : public B
{
public:
    A();
    explicit A(SomeThing *arg=defaultArg);
    A(int a, int b);
    ~A();

    void someFunc() const;
    void someFunc(bool a, int b);
    void booyaaahhh();
private:
    int _privateIntMember;
    double *_privateDoublePointerMember;
};

}

#endif // GUI_A_H

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to