View Poll Results: How many spaces do you indent your code?

Voters
68. You may not vote on this poll
  • 1 space

    4 5.88%
  • 2 spaces

    21 30.88%
  • 3 spaces

    13 19.12%
  • 4 spaces

    33 48.53%
  • 5 spaces

    7 10.29%
  • 6 spaces

    5 7.35%
  • 7 spaces

    4 5.88%
  • 8 spaces

    8 11.76%
  • Other

    7 10.29%
Multiple Choice Poll.

Thread: How far do you indent?

  1. #16
    Nonconformist Narf's Avatar
    Join Date
    Aug 2005
    Posts
    174
    If your lines are too long it's not the tab size that is the problem.
    Yea, that would be the fault of a stupidly verbose standard library.
    Just because I don't care doesn't mean I don't understand.

  2. #17
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    voted everything

  3. #18
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    When you tab in Dev-C++, it puts multipule spaces according to the line above or below the line you are tabing. (I tab.)

  4. #19
    Dump Truck Internet valis's Avatar
    Join Date
    Jul 2005
    Posts
    357
    I use tab, with any modern editor you can setup so much tab stuff it allows one to have their own spacing style.

  5. #20
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Quote Originally Posted by dwks
    One of my books suggests that you shouldn't go over three levels of indentation, but I don't go that far.
    Namespace
    >> Class
    >>>> Function

    So you can only have one level deep if statements and loops. No if's in a loop or loops in an if, or a single nested if.

    No one can really set a hard and fast rule like that. I always set the IDE to replace tabs with 4 spaces though. Using plain tabs makes a huge mess if someone else used spaces - if the tab size is set to 4 it might look ok, but if it's say 8, things get very ugly.

  6. #21
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Quote Originally Posted by dwks
    If they "add up quickly", modularize your program (ie, break it up into functions). One of my books suggests that you shouldn't go over three levels of indentation, but I don't go that far.

    But I think 8 is too much, for all that.
    Good in theory, but I find that it is not always practical.

    I use three. I find two to be too little (that was a fun sentence), and more than four excessively obnoxious. Between three and four, I prefer three.
    The word rap as it applies to music is the result of a peculiar phonological rule which has stripped the word of its initial voiceless velar stop.

  7. #22
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    I voted 4 and 8 spaces. It all depends what platform I'm working on (either solo or in a team).

    When writing for Windows I usually stick to the 4 space standard, and 8 for Linux.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  8. #23
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Quote Originally Posted by dwks
    Well, if you transfer it, it sometimes ends up looking like this:

    Code:
    int main(void) {
                         if(1) {
                          printf("hi");
                }
                      return 0;
         }
    Stop using the Kernel style then, Allman all the way!
    Also, don't mix spaces with tabs. Use one or the other, not both.

    I use 3 or 4, whatever is standard in VC2003.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #24
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,829
    Coding standards at your house will decide. Left to me 4 spaces.
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  10. #25
    FOX
    Join Date
    May 2005
    Posts
    188
    8 space tabs all the way. Indentation is meant to make the code more readable, and IMO 4 spaces just isn't enough.

    I also prefer tabs over spaces since it consumes less space (not a big issue though), and it lets whoever is working on my code display it how they like without having to re-indent the whole file.

    Here's a tip for you VIM users who can't paste properly.
    Code:
    :set paste

  11. #26
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Quote Originally Posted by ^xor
    8 space tabs all the way. Indentation is meant to make the code more readable, and IMO 4 spaces just isn't enough.

    I also prefer tabs over spaces since it consumes less space (not a big issue though), and it lets whoever is working on my code display it how they like without having to re-indent the whole file.

    Here's a tip for you VIM users who can't paste properly.
    Code:
    :set paste
    Thanks for the VIM tip, I can never get it to past right
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  12. #27
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    2 for C and C++ and Perl and Java and HTML, 4 for Visual Basic. hehe.

  13. #28
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Quote Originally Posted by Zach L.
    Good in theory, but I find that it is not always practical.

    I use three. I find two to be too little (that was a fun sentence), and more than four excessively obnoxious. Between three and four, I prefer three.
    Three spaces for me also. I tried two in another programming language I use, but never could get used to it, so I switched back to three.

  14. #29
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    4 spaces, though with a tab.

    I find using an odd number of spaces odd, for some reason.
    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. #30
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,820
    4. Just typing this
    Woop?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Weird Strings??
    By Paul22000 in forum C++ Programming
    Replies: 12
    Last Post: 07-14-2008, 01:02 PM
  2. array comparison
    By battoujutsu in forum C Programming
    Replies: 12
    Last Post: 12-05-2003, 11:47 AM
  3. Visual C++
    By Golffor1 in forum C++ Programming
    Replies: 1
    Last Post: 08-04-2003, 04:30 PM
  4. how to indent a file.
    By hakim12 in forum C++ Programming
    Replies: 2
    Last Post: 01-30-2003, 02:55 PM
  5. Indent code
    By boontune in forum C++ Programming
    Replies: 3
    Last Post: 01-23-2003, 11:27 AM