View Poll Results: Do you prefer to use spaces, or tabs to indent your code?

Voters
53. You may not vote on this poll
  • Spaces

    22 41.51%
  • Tabs

    28 52.83%
  • Other

    3 5.66%
Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 33

Thread: Spaces or Tabs?

  1. #21
    Join Date
    Jun 2005
    Location
    England
    Beans
    2,726

    Re: Spaces or Tabs?

    Tabs all the way, far, far less fiddely than spaces and everyone seems to use weird amounts with spaces....

  2. #22
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Spaces or Tabs?

    Quote Originally Posted by Simian Man View Post
    I never want to work on a project with you .
    Hey, that convention was set long before I was born; I just follow it. And I stick to the standards of the project I'm working on when such standards exist.

  3. #23
    Join Date
    Mar 2005
    Beans
    947
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Spaces or Tabs?

    Quote Originally Posted by Zugzwang View Post
    Every piece of code should be well readable with any tab-setting
    Not when tabs are mixed with spaces. That's what we're talking about here.

    Not that I'm really fond of the idea of code looking different in different editors, even with pure tabs. I'm sad to see tabs winning the poll right now.

    Quote Originally Posted by trent.josephsen View Post
    Which is why setting tabstops to anything other than 8 spaces is a bad idea.
    And yet, you yourself said that you used to set them to four. Anyway, it's not always an option. (I've even seen at least one semi-popular editor that doesn't handle tabs properly at all, treating them as fixed numbers of spaces rather than moving to the next tab stop.)

    Like I said, I used to do what you're doing. And I saw my formatting messed up enough times to realize it was a bad idea.

  4. #24
    Join Date
    Sep 2006
    Location
    Solihull/Piraeus (UK/GR)
    Beans
    421
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Spaces or Tabs?

    Quote Originally Posted by wmcbrine View Post
    ...and consistency is impossible to achieve when mixing spaces and tabs.
    I don't think that any perfect solution exists unfortunately. Ideally everyone would just use tabs and then indents can be consistently as big or small as each of us likes.

    But invariably with collaborative development, sooner or later someone will mix it. So I think the best "rule" is not to have a rule and just try to remain consistent with what's used in each file as it comes.

    For my own purposes, I find code easier to read in a terminal using indentation with 2 spaces, so that's my default setting. I would expect that to be unpopular but, frankly, I've never found any alternative strategy to work out either better or worse for promoting consistency in reality...somebody will screw it up whatever you do.

    And if they don't screw up the indentation, they'll do something else you think is ugly with the layout of conditional blocks, curly braces, line lengths, naming etc.

    This is just one of the things we have to learn to live with, especially in the FOSS world Difficult when most programmers are naturally pedantic about this stuff (myself included).

  5. #25
    Join Date
    Feb 2009
    Beans
    1,469

    Re: Spaces or Tabs?

    I revoke my former statements and reluctantly see the error of my ways. Tabs FTW.

  6. #26
    Join Date
    Nov 2009
    Location
    The Netherlands
    Beans
    239
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Spaces or Tabs?

    Quote Originally Posted by xsinsx View Post
    Use spaces preferably but all my editors are setup that a tab is equal to 4 spaces so i have the benefit of the one key for a set of spaces
    That exactly, also:
    Code:
    sed -e 's/\t/    /g' -e 's/[[:blank:]]*$//' -e 'a\'

  7. #27
    Join Date
    Dec 2006
    Beans
    Hidden!

    Re: Spaces or Tabs?

    Quote Originally Posted by wdaniels View Post
    I don't think that any perfect solution exists unfortunately. Ideally everyone would just use tabs and then indents can be consistently as big or small as each of us likes.

    But invariably with collaborative development, sooner or later someone will mix it. ...
    Yes. The problem is mixing. The problem is also that most people don't make a distinction between "indentation" and "alignment" of code.

    Indentation refers to the amount of white space at the beginning of a line, while alignment refers to any other white space in the line to accommodate the text with a previous line, this is where most horrors happen.

    Code:
    def f():
        This is indented
        Four-spaces indentation (assume it's a tab)
    1234    1234    1234    1234    1234
        1234    1234    1234    1234
        |   |   |   |   |   |   |   |
        |   |   |   |   |   |   |   |
        int boo     =   56 ; /* There are two tabs */
        int bas     =   10 ; /* before the equals sign */
        char[] var  =   "There is one tab before the equals sign" ;
        /* There is one tab after each equals sign */

    Now change it to 6-spaces tab.
    Code:
    def f():
          This is indented
          Six-spaces indentation (assume it's a tab)
    123456      123456      123456      123456
          123456      123456      123456
          |     |     |     |     |     |
          |     |     |     |     |     |
          int boo           =     56 ; /* Still two tabs */
          int bas           =     10 ; /* before the equals sign */
          char[] var  =     "Still one tab, and it no longer aligns" ;
    The indentation remains one tab, and it looks good. But the lines no longer align at the "=" character.

    The alignment problem can be solved by always using spaces, without worrying about the amount of space used for indentation.

    Again with six-spaces indentation, but using spaces for alignment:
    Code:
    def f():
          This is indented
          Six-spaces indentation (assume it's a tab)
    123456      123456      123456      123456
          123456      123456      123456
          |     |     |     |     |     |
          |     |     |     |     |     |
          int boo     =     56 ; /* Five spaces before the sign */
          int bas     =     10 ; /* Five spaces before the sign */
          char[] var  =     "Two spaces before the sign"
          /* The space after the sign could be a tab */
          /* and it wouldn't affect the alignment */
    Now with 9-spaces tabs.
    Code:
    def f():
             This is indented
             Crazy 9-spaces indentation (assume it's a tab)
    123456789         123456789         123456789
             123456789         123456789
             |        |        |        |
             |        |        |        |
             int boo     =     56 ; /* Five spaces before the sign */
             int bas     =     10 ; /* Still aligns okay! */
             char[] var  =     "Two spaces before the sign"
             /* The space after the sign is a tab */
             /* and it doesn't affect the alignment */
             /* because the reference is the "=" sign, */
             /* which is correctly positioned with spaces */
    I'm not sure if everybody gets my example.

    In summary, understand the difference between indenting (at the beginning of a line), and aligning (everywhere else).

    For indenting you can use tabs or spaces (be consistent!). For alignment you should only use spaces!

  8. #28
    Join Date
    Sep 2006
    Location
    Solihull/Piraeus (UK/GR)
    Beans
    421
    Distro
    Ubuntu 11.10 Oneiric Ocelot

    Re: Spaces or Tabs?

    Quote Originally Posted by Vox754 View Post
    The problem is also that most people don't make a distinction between "indentation" and "alignment" of code.
    Ah yes, a very good point. This is probably the worst of all actually now that I think about it...people using a small tab size then use tabs to align something about 30 spaces in from the block "indent", so then when someone else opens it with 4 or 8 tab size sometimes the "aligned" code is so far off to the right you don't even see it

    Even if we were to invent a set of fancy language parsers for all the editors that would redo the layout of the entire source file according to the parse-tree structure, you would still never be able to sort out this problem with tabbed alignment, except to remove any alignment at all!

    I've never been a fan of "significant white space" in languages, but perhaps it is the only way to enforce a solution to this perpetual aggravation. And when I think about it like that I always conclude that messed up formatting is the lesser of the two evils and I curse myself for being such a pedant.

  9. #29
    Join Date
    Dec 2006
    Beans
    Hidden!

    Re: Spaces or Tabs?

    Quote Originally Posted by wdaniels View Post
    Ah yes, a very good point. This is probably the worst of all actually now that I think about it...people using a small tab size then use tabs to align something about 30 spaces in from the block "indent", so then when someone else opens it with 4 or 8 tab size sometimes the "aligned" code is so far off to the right you don't even see it ...
    Happens in this same forum.

    People use tabs to indent, and in their editor they (unknowingly) use 2 spaces expansion. Then they post code in this forum, which auto-expands to the classical 8 spaces.

    So when people indent, in their own mind to 4 spaces, they actually use 2 tabs, or 16 spaces in this forum.

    I've seen code like this here:
    Code:
    for (i = 0 ; i < 99 ; ++i) {
                    for (i = 0 ; i < 99 ; ++i) {
                                    if ( bla == 456)
                                                    break ;
                    }
    }
    And then they are like, "lol, I don't no what's wrong with the spacing, sorry guyz, Windows sucks, lol"

  10. #30
    Join Date
    Apr 2007
    Location
    NorCal
    Beans
    1,149
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Spaces or Tabs?

    Quote Originally Posted by Vox754 View Post
    Code:
    for (i = 0 ; i < 99 ; ++i) {
                    for (i = 0 ; i < 99 ; ++i) {
                                    if ( bla == 456)
                                                    break ;
                    }
    }
    And then they are like, "lol, I don't no what's wrong with the spacing, sorry guyz, Windows sucks, lol"
    If you look at your example, there's bigger problems than just spacing.
    Posting code? Use the [code] or [php] tags.
    I don't care, I'm still free. You can't take the sky from me.

Page 3 of 4 FirstFirst 1234 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •