Consensus on the kdelibs coding style

Thiago Macieira thiago at kde.org
Sun Jul 6 16:32:50 BST 2008


Kelly Miller wrote:
>On July 5, 2008 9:41:23 am Lubos Lunak wrote:
>> - "4 spaces, no tabs" - this appears to be the most used style in
>> kdelibs, and other options don't seem to have big advantages
>
>Can someone explain to me what's so evil about tabs?  Personally, I hate
>stumbling across spaced code indents, because they're horribly
> inflexible, can't be resized at all, and require the programmer in
> question to remember to hit the space key X times for an indent.

Well, if you have to press the space bar, you should change editors. Good 
editors indent automatically, to the proper level.

The problem with tabs is that the correct way to use it is not followed. 
To use Tabs correctly, you must make the distinction between indentation 
and alignment. When indenting code, you use one tab more than the 
previous level. When aligning code, you use spaces. And you don't mix 
them.

For example:
int main(int argc, char **argv)
{
[tab]if (argc >=2 &&
[tab]    strcmp(argv[1], "--help"))
[tab]{
[tab][tab]showHelp("programname",
[tab][tab]         "0.1");
[tab][tab]return 0;
[tab]}
}

Note how the continuations to the if and the arguments to showHelp() are 
aligned using spaces, not tabs. Note as well that "showHelp(" is 9 
characters, but there aren't ANY tabs under it in the next line.

Most editors would replace the 9 spaces with 1 Tab + 1 Space (if tabs have 
the default width of 8 spaces). That's what breaks indentation. And even 
if your editor works correctly, not all do. And they'll tabify lines you 
touch (even if you leave it unchanged later). So, in order to use tabs, 
we need EVERYONE's text editors, both current and future developers, to 
be configured like above.

That's why Tabs are evil. That's why they should be banned completely and 
removed from KDE code.

Of course, we have to ask everyone to turn tabbing off in their editors, 
but that's a much easier thing to do than to use formatting like above.
-- 
  Thiago Macieira  -  thiago (AT) macieira.info - thiago (AT) kde.org
    PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080706/d59e20f8/attachment.sig>


More information about the kde-core-devel mailing list