View Poll Results: How do you indent?

Voters
34. You may not vote on this poll
  • Tabs

    19 55.88%
  • 1 space per level

    0 0%
  • 2 or 3 spaces per level

    6 17.65%
  • 4 through 6 spaces per level

    7 20.59%
  • 7+ spaces per level

    2 5.88%

Thread: How do you indent: spaces or tabs?

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262

    How do you indent: spaces or tabs?

    Another thread was about this, I was just wondering: how do you indent your source code?
    I prefer indenting with two spaces.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    4 spaces. I used to use tabs until I realized it made the source code look different depending on what application was viewing it.
    bit∙hub [bit-huhb] n. A source and destination for information.

  3. #3
    Banned ಠ_ಠ's Avatar
    Join Date
    Mar 2009
    Posts
    687
    2 spaces
    ╔╗╔══╦╗
    ║║║╔╗║║
    ║╚╣╚╝║╚╗
    ╚═╩══╩═╝

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    @Echo bithub
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I bet a bunch of newbies are going to read this thread and be like "huh? wuzzat???".

    Anyway, one tab or 6 spaces.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    So, we need to periodically hold this poll so as to determine some trend?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Oct 2008
    Posts
    1,262
    Quote Originally Posted by laserlight View Post
    So, we need to periodically hold this poll so as to determine some trend?
    Actually, that's not a bad idea.
    I didn't know this poll already existed. Although, honestly, I'm not surprised.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Well, there seems to be several threads about indent style, but the one that most closely matches this poll is... How far do you indent?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by laserlight View Post
    So, we need to periodically hold this poll so as to determine some trend?
    I think this would be a good idea. It would allow us to see how everyone slowly trends from their imperfect indentation style, to the correct style of 4 spaces over time
    bit∙hub [bit-huhb] n. A source and destination for information.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I use tabs (set to the width of 4 spaces) because we use Visual C++ exclusively for our coding and tabs are easiest to work with.

    On personal projects I often set my editor to convert tabs to spaces (still at 4 spaces per tab). For code I post on forums I have a macro that converts all tabs to 4 spaces that I run before posting since tabs don't look so good on these forums.

  11. #11
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I'd like to add that one space just isn't sufficient. On a side note, I wonder if anyone indents using only semicolens?

  12. #12
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    I follow Linus's lead:
    Quote Originally Posted by Linus Torvalds
    Chapter 1: Indentation

    Tabs are 8 characters, and thus indentations are also 8 characters.
    There are heretic movements that try to make indentations 4 (or even 2!)
    characters deep, and that is akin to trying to define the value of PI to
    be 3.

    Rationale: The whole idea behind indentation is to clearly define where
    a block of control starts and ends. Especially when you've been looking
    at your screen for 20 straight hours, you'll find it a lot easier to see
    how the indentation works if you have large indentations.

    Now, some people will claim that having 8-character indentations makes
    the code move too far to the right, and makes it hard to read on a
    80-character terminal screen. The answer to that is that if you need
    more than 3 levels of indentation, you're screwed anyway, and should fix
    your program.

    In short, 8-char indents make things easier to read, and have the added
    benefit of warning you when you're nesting your functions too deep.
    Heed that warning.

    The preferred way to ease multiple indentation levels in a switch statement is
    to align the "switch" and its subordinate "case" labels in the same column
    instead of "double-indenting" the "case" labels. E.g.:
    Code:
            switch (suffix) {
            case 'G':
            case 'g':
                    mem <<= 30;
                    break;
            case 'M':
            case 'm':
                    mem <<= 20;
                    break;
            case 'K':
            case 'k':
                    mem <<= 10;
                    /* fall through */
            default:
                    break;
            }
    Don't put multiple statements on a single line unless you have
    something to hide:

    if (condition) do_this;
    do_something_everytime;

    Don't put multiple assignments on a single line either. Kernel coding style
    is super simple. Avoid tricky expressions.

    Outside of comments, documentation and except in Kconfig, spaces are never
    used for indentation, and the above example is deliberately broken.

    Get a decent editor and don't leave whitespace at the end of lines.

  13. #13
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    When I'm indenting blocks of code like functions, conditionals, etc... I use tabs.

    When I'm trying to get various parts of the code to line up (like when I have very similar lines of code and I want to emphasize their similiarity and clarify the different parts of each line, I use spaces (that way it doesn't get messed up if someone uses 4-space-tabs instead of my 8-space-tabs).

    edit: Linus Torvalds endorses my 8-space-tabs? YES!

  14. #14
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by sean
    edit: Linus Torvalds endorses my 8-space-tabs? YES!
    That just makes the three of you heathens
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #15
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Who is Linus Torvalds?

    EDIT: Just found it on Wikipedia. Didn't look too impressive. But 8 space tabs surely look impressive on C++ generic programming...
    Last edited by Mario F.; 09-22-2009 at 11:41 AM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing 3 spaces to tabs
    By dnguyen1022 in forum C Programming
    Replies: 2
    Last Post: 12-22-2008, 12:51 AM
  2. Tabs or Spaces
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 46
    Last Post: 04-08-2007, 11:45 AM
  3. Visual C++
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2003, 04:30 PM
  4. tabs to spaces with dev c++ v.4
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 02:07 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM