Coding Style: indenting with tabs vs. spaces - Kernel

This is a discussion on Coding Style: indenting with tabs vs. spaces - Kernel ; Greetings, I would like to hear peoples opinion about the indentation convention described below that I personally found the most practical with several different editors. The gist of it is that tabs should be used for nesting, not for decoration. ...

+ Reply to Thread
Results 1 to 11 of 11

Thread: Coding Style: indenting with tabs vs. spaces

  1. Coding Style: indenting with tabs vs. spaces

    Greetings,

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

    The gist of it is that tabs should be used for nesting, not for decoration.
    Indent your code with as many tabs as your nesting level, where all statements
    will begin, and from there on use space characters.
    The rational behind it is to be tab-width agnostic so regardless of your
    tab expansion setup, the code will look correct and will make sense.

    When you break a line and want the new line text to start below a specific point
    relative to the previous line (I consider that "decorating") then start the new
    line with the same number of tabs as the previous one and then just use space
    characters as their width is the same as any character in the previous line,
    (assuming fixed-width fonts of course).

    For example:

    {
    if (very_long_expression &&
    it_needs_to_be_broken_into_several_lines)
    return a_very_long_result +
    the_remainder_of_it_that_spilled_off +
    to_the_next_lines;

    return printk("just my %d cents\n",
    2);
    }

    Thanks,

    Benny

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

  2. Re: Coding Style: indenting with tabs vs. spaces

    Benny Halevy wrote:
    > Greetings,
    >
    > I would like to hear peoples opinion about the indentation convention
    > described below that I personally found the most practical with
    > several different editors.
    >
    > The gist of it is that tabs should be used for nesting, not for decoration.
    > Indent your code with as many tabs as your nesting level, where all statements
    > will begin, and from there on use space characters.
    > The rational behind it is to be tab-width agnostic so regardless of your
    > tab expansion setup, the code will look correct and will make sense.
    >
    > When you break a line and want the new line text to start below a specific point
    > relative to the previous line (I consider that "decorating") then start the new
    > line with the same number of tabs as the previous one and then just use space
    > characters as their width is the same as any character in the previous line,
    > (assuming fixed-width fonts of course).


    I find it meaningful to indent extended lines one extra tab stop, but beyond
    that I agree it is just decoration.

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

  3. Re: Coding Style: indenting with tabs vs. spaces

    Hi Benny

    * Benny Halevy 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.

    So my opinion is: use spaces. The code indentation will look the same on
    every editor no matter the tab settings.

    Raúl Núñez de Arenas Coronado

    --
    Linux Registered User 88736 | http://www.dervishd.net
    It's my PC and I'll cry if I want to... RAmen!
    We are waiting for 13 Feb 2009 23:31:30 +0000 ...
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  4. Re: Coding Style: indenting with tabs vs. spaces


    Le samedi 10 novembre 2007 13:04 +0100, DervishD a crit :
    > Hi Benny
    >
    > * Benny Halevy 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 ?
    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.

    Xav


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

  5. Re: Coding Style: indenting with tabs vs. spaces

    Bonjour Xavier

    * Xavier Bestel dixit:
    > Le samedi 10 novembre 2007 * 13:04 +0100, DervishD a écrit :
    > > * Benny Halevy 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

    --
    Linux Registered User 88736 | http://www.dervishd.net
    It's my PC and I'll cry if I want to... RAmen!
    We are waiting for 13 Feb 2009 23:31:30 +0000 ...
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  6. Re: Coding Style: indenting with tabs vs. spaces

    On Nov. 10, 2007, 14:27 +0200, Xavier Bestel wrote:
    > Le samedi 10 novembre 2007 13:04 +0100, DervishD a crit :
    >> Hi Benny
    >>
    >> * Benny Halevy 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 ?
    > 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.


    Right. That's exactly the point.
    I find it harder to read someone else's code if (s)he uses 2 space indentation.
    With tabs, when done right, I can expand to my personal preference.

    >
    > Xav
    >
    >

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

  7. Re: Coding Style: indenting with tabs vs. spaces

    DervishD wrote:
    > Bonjour Xavier
    >
    > * Xavier Bestel dixit:
    >
    >> Le samedi 10 novembre 2007 * 13:04 +0100, DervishD a écrit :
    >>
    >>> * Benny Halevy 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?

    James


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

  8. Re: Coding Style: indenting with tabs vs. spaces

    On Nov. 08, 2007, 17:58 +0200, Chris Snook wrote:
    > Benny Halevy wrote:
    >> Greetings,
    >>
    >> I would like to hear peoples opinion about the indentation convention
    >> described below that I personally found the most practical with
    >> several different editors.
    >>
    >> The gist of it is that tabs should be used for nesting, not for decoration.
    >> Indent your code with as many tabs as your nesting level, where all statements
    >> will begin, and from there on use space characters.
    >> The rational behind it is to be tab-width agnostic so regardless of your
    >> tab expansion setup, the code will look correct and will make sense.
    >>
    >> When you break a line and want the new line text to start below a specific point
    >> relative to the previous line (I consider that "decorating") then start the new
    >> line with the same number of tabs as the previous one and then just use space
    >> characters as their width is the same as any character in the previous line,
    >> (assuming fixed-width fonts of course).

    >
    > I find it meaningful to indent extended lines one extra tab stop, but beyond
    > that I agree it is just decoration.


    Yup, that's a valid convention, as long as there are no trailing spaces after that
    extra tab stop. Concatenating spaces to this one extra tab stop (as checkpatch
    allows for up to 7 spaces) for decoration works well just as long as everybody
    expand tabs the same way.

    Benny

    >
    > -- Chris
    > -


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

  9. Re: Coding Style: indenting with tabs vs. spaces

    On Nov. 11, 2007, 11:23 +0200, James Courtier-Dutton wrote:
    > DervishD wrote:
    >> Bonjour Xavier
    >>
    >> * Xavier Bestel dixit:
    >>
    >>> Le samedi 10 novembre 2007 * 13:04 +0100, DervishD a écrit :
    >>>
    >>>> * Benny Halevy 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@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

  10. Re: Coding Style: indenting with tabs vs. spaces

    On Mon, Nov 12, 2007 at 10:13:08AM +0200, Benny Halevy wrote:
    > 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.


    The tabs-for-indent, spaces-for-alignment policy been proposed before;
    this:

    http://marc.info/?t=119251728100004&r=1&w=2

    was only on the git mailing list, but we could probably dig up similar
    discussions on lkml with some more work.

    Speaking as someone who doesn't care, but doesn't see it as a
    particularly interesting discussion, either....

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

  11. Re: Coding Style: indenting with tabs vs. spaces

    Hi Benny

    * Benny Halevy dixit:
    > 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 admit it.

    > 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.


    Yes, you're right, and it is the only "mix" of tabs and spaces that
    won't cause headaches. I still don't like tabs for indenting but that's
    a matter of personal taste. Sometimes I use tabs for indenting when I
    have to share code.

    Raúl Núñez de Arenas Coronado

    --
    Linux Registered User 88736 | http://www.dervishd.net
    It's my PC and I'll cry if I want to... RAmen!
    We are waiting for 13 Feb 2009 23:31:30 +0000 ...
    -
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to majordomo@vger.kernel.org
    More majordomo info at http://vger.kernel.org/majordomo-info.html
    Please read the FAQ at http://www.tux.org/lkml/

+ Reply to Thread