Re: Coding Style: indenting with tabs vs. spaces



On Nov. 11, 2007, 11:23 +0200, James Courtier-Dutton <James@xxxxxxxxxxxxxx> wrote:
DervishD wrote:
Bonjour Xavier :)

* Xavier Bestel <xavier.bestel@xxxxxxx> dixit:

Le samedi 10 novembre 2007 à 13:04 +0100, DervishD a écrit :

* Benny Halevy <bhalevy@xxxxxxxxxxx> dixit:

I would like to hear peoples opinion about the indentation convention
described below that I personally found the most practical with
several different editors.

While I respect you opinion about tabs, I find tab indentation the most
evil thing ever invented. Even if done right (that is, not indenting
using a mixture of spaces and tabs), the only advantage is that you save
a few bytes.

Who cares ?

About the space saving? Not me, of course. It's just that I didn't see
any other advantage.


The only advantage is that people can make tabs as big (or as small)
as they wish. Tabs become "logical indentation". So one's indentation
isn't forced on anotherone's editor.

The only way of having a sane indentation using tabs is to make sure
that ALL indentation are tabs, not a mix of tabs and spaces (spaces, if
any, should be at the end of indentation for aesthetical purposes, but
should be removed without the logical indentation being lost). A good
editor can ensure that all indentation are tabs and not a mix, but a
good editor can adapt indentation to your likings when loading the file
and save the file translating your favourite indentation back to spaces
or whatever.

If everybody used tabs correctly, indenting using tabs would be great,
but IMHO indenting with spaces is much better.

Raúl Núñez de Arenas Coronado



Just use the linux

./scripts/checkpatch.pl --file

It does all the indent checks for you before you submit a patch.
I.e. I checks that one has not mixed tabs with spaces etc.
So, any patches to the Linux kernel will have tabs used correctly.
Where is the problem?

checkpatch allows to indent with any number of tabs and up to 7 spaces.
This is consistent with Documentation/CodingStyle and therefore can be
considered "correct". However, forcing everybody to the same tab expansion
setup is too limiting, especially when working in several environments
at the same time where some of them may not be the linux kernel.

Using only spaces as DervishD suggested works around that using brute force
by forcing the user to the author's preference which is legitimate but
may not be the most productive way.

I think that my proposal of using tabs as logical indents only (as Xav put it)
and spaces for decorative alignment provides the best of both worlds.
One can expand the tabs to any number of spaces as one likes and then
the trailing spaces will work on any editor setup as long as you use
fixed-width font. That's not considered "correct" as per checkpatch but
works much better for me.

Benny


James


-

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: AfxGetApp() returns NULL
    ... VS to edit my code, it gets the identation right, following my indentation ... OPTION of whether to use spaces or tabs. ... me, and written using my editor, and given away free to others as a courtesy, I see no ... of my automation; worse still, the creators of VS think that there is no ...
    (microsoft.public.vc.mfc)
  • Re: A stylistic question.
    ... spaces of indentation is almost too little for my taste. ... something other than 8 means that anything containing tabs will look ... My preferred text editor, vi, has ... I don't "mess around with spaces"; ...
    (comp.lang.c)
  • Re: Request for comment on my tiny learning project: dfighterdb (mytree)
    ... -In most of your code I looked at, your closing braces line up with ... -Your code uses tabs for indentation. ... The cast is unnecessary. ... I don't do the indentation myself. ...
    (comp.lang.c)
  • Re: Tabs vs. Spaces
    ... > everyone who reads my code has to suffer from my indentation style. ... code and view it on a viewer with 2-space tabs). ... programmers in general hate tabs. ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Using TABs vs. spaces II. (the Philosophy flamewar reloaded ;-))
    ... I read somewhere that good-style Ruby code is indented by 2 spaces. ... code if the indentation is only at 2 spaces. ... spaces or just tabs rather than switching between the two. ... You can alter tab length in your editor (for at least most editors, ...
    (comp.lang.ruby)