Consensus on the kdelibs coding style
Lubos Lunak
l.lunak at suse.cz
Sat Jul 5 16:24:03 BST 2008
On Saturday 05 of July 2008, Thiago Macieira wrote:
> Lubos Lunak wrote:
> >which defines even completely useless things like
> >requiring {}'s around a single-line if() body statement (where's the
> > point in that?), I'd prefer something simple.
>
> Just for information, that requirement is not in the Qt style. That's
> actually one of modifications that was added to the KDE Libs style on top
> of the Qt style. If you look at Qt code, you'll see that is not used.
I wonder how it got there then, especially when the proponents seemed quite
strict on "no modifications".
> Anyways, regarding your proposal, I'll say what most other people will
> say: I disagree in certain points, but having one *single* style is
> better than having none, whatever the style is (as long as it makes
> sense, of course).
And that's also what was agreed on in Trysil (and that includes me). What was
not agreed on was "whatever the styles is, as long as it is the Qt style" as
it was presented.
> The major point is actually deciding on the "4 spaces, NO TABS"
> (capitalisation mine, but should be there). Tabs are inherently evil and
> should be banned altogether, to the point of warranting a wide-reaching
> tab-replacement commit (svn can now ignore whitespace changes in
> annotation, git has been able to do it for years).
Well, at least one thing we hopefully can all agree on :). I was actually
originally hoping this would be how it'd be done, starting with the major
problems, finding an acceptable solution, advancing to the less important and
more problematic to agree on, and seeing how far we get.
(And you'd get my vote on the one big commit with tabs->spaces.)
> A distant second is the placement of the braces. Your style is closer to
> my own preferred style, actually, but I'd still advocate for matching
> Qt's simply because of pragmatism.
Which pragmatism? A small number of people working on Qt and KDE at the same
time, or some other codebase which uses it? According to my search on kdecore
and kdeui there is a slight preference for trailing { (i.e. Qt), but it's not
vast majority and I think that strictly technically speaking aligned {} are
better for readability (e.g. in the switch/case unindented case, a trailing {
seems quite hard to see).
> The only thing I don't like in your code is the indentation of label-like
> constructs (case labels and public/protected/private) because of this:
>
> class Foo
> {
> Foo();
It's not a nice style to do this :), and I wanted to have the rule as simple
and consistent as possible. But it seems no indentation here is what most .h
files in kdelibs use, so I guess I don't have a good argument here except for
consistency (and that's a lost case with C/C++ anyway, right?).
> So I'd go for "label-like constructs are de-indented one level":
>
> switch (a)
> {
> case 'a':
> break;
> }
>
> This would again match the Qt style.
What would be the reason for this? As already pointed out, this can be
potentially less readable, and it loses also the more-used argument (60 vs 79
in kdecore, 66 vs 99 in kdeui [1]).
> So, that's it. As long as we can agree on one style and actually enforce
> it, I'll be happy.
Yes. Which is why I decided to write the mail instead of trying to shrug off
the issue again. I don't think the current approach is going to get us there,
with suddenly such a strict change that most people won't follow anyway,
either because of disagreement in general or just because the current style
lists too many things, important ones next to details like 'QObject *foo'
vs 'QObject* foo' (BTW, the first one is a C-ism, the C++ way should be the
second, especially with one-var-per-line anyway, but I don't think that
matters now - the day such things are significant we don't have serious
coding style problems anymore).
[1] find . -name '*.cpp' | xargs cat | grep -e 'switch
*(' -e 'case.*:' -e 'default *:' | less [and counting manually]
--
Lubos Lunak
KDE developer
--------------------------------------------------------------
SUSE LINUX, s.r.o. e-mail: l.lunak at suse.cz , l.lunak at kde.org
Lihovarska 1060/12 tel: +420 284 028 972
190 00 Prague 9 fax: +420 284 028 951
Czech Republic http://www.suse.cz
More information about the kde-core-devel
mailing list