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%

How do you indent: spaces or tabs?

This is a discussion on How do you indent: spaces or tabs? within the General Discussions forums, part of the Community Boards category; Originally Posted by Prelude >I note that this thread is about the amount by which one indents, not >about whether ...

  1. #31
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Prelude View Post
    >I note that this thread is about the amount by which one indents, not
    >about whether one indents with space characters or tab characters.

    The amount is far more interesting. But I use real spaces because the amount is small enough that there's really no difference between tabbing once and spacing twice. If I used an indent of four or more spaces, I would be more inclined to switch to tabs.
    I used to do that. . . then I started writing real code and it got sooooo ugly and unreadable that I just couldn't do it anymore. But, I use vim as my editor so (in the old days) I was stuck to two spaces = two spaces and not an indent.

    Someone coding with two spaces should be taken out an horse whipped. just kidding.

  2. #32
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by Memloop View Post
    I like tabs and always keep my code 80 characters wide at most. Only one problem though: Let's say your company has a rule that code should not be more than 80 characters wide, and you start using tabs that are only 4 characters wide. What happens when someone who likes their tabs to be 8 characters wide opens your file and find that every other line soft wraps or disappears into the marginal?
    Then the company policy is incomplete. If you specify that tabs must be used, AND that lines are to be viewed at 80 columns, then you MUST specify the tab width or your specification is incomplete (obviously).

    Here, since we do not specify specific tab width, we therefore leave line length unspecified as well.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #33
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >then I started writing real code and it got sooooo ugly
    >and unreadable that I just couldn't do it anymore

    Real code gets out of hand quickly, not because of stylistic choices (assuming those choices are reasonable), but because real code is complicated and always evolving. It takes more work to keep it clean and readable, regardless of how much you indent.
    My best code is written with the delete key.

  4. #34
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Prelude View Post
    >then I started writing real code and it got sooooo ugly
    >and unreadable that I just couldn't do it anymore

    Real code gets out of hand quickly, not because of stylistic choices (assuming those choices are reasonable), but because real code is complicated and always evolving. It takes more work to keep it clean and readable, regardless of how much you indent.
    True that. One of the other paragraphs in Linus's coding style document (in the Linux code) says that one must keep functions short and to one point. If a function is longer than a screen shot (25 lines), then the function is probably too complicated (except for the case in which the function does IO or has a nasty switch statement handling many cases).

    I've tried my very best to adhere to what Linus wrote -- his was a morph of the K&R style -- which they didn't teach at JSU -- we were just kinda left to our own devices about the style of our code.

  5. #35
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,627
    I'm pretty sure my editor uses tabs, so I use tabs, still, and always. In fact I expect my code indented whenever I type a brace and press enter. The length usually looks like 4 spaces but it's actually 8 spaces.

  6. #36
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Kennedy View Post
    I follow Linus's lead:
    Quote Originally Posted by L.T.
    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.
    Is the fact that you can no longer see straight supposed to be some sort of justification here? I mean I sometimes like marathon sessions but I would not use them as an excuse ("after 5 hits of acid and a case of beer, you'll find it a lot easier to see how the indentation works if you have large indentations"). If you are becoming confused by 4 char tabs, please call it a night.

    I use tabs set to 4 characters but I don't care much, 2, 4, or 8 is fine. I switched from 8 to 4 because a block nested 6 or 7 levels deep is so far inset that you must start scrolling horizontally for long lines. I didn't vote because the poll seems flawed to me, insofar as it contrasts "a tab" with any number of spaces.

    I'll draw the line at one, tho. 1 character is not indentation.
    Last edited by MK27; 09-22-2009 at 03:09 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  7. #37
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by MK27 View Post
    Is the fact that you can no longer see straight supposed to be some sort of justification here? I mean I sometimes like marathon sessions but I would not use them as an excuse ("after 5 hits of acid and a case of beer, you'll find it a lot easier to see how the indentation works if you have large indentations"). If you are becoming confused by 4 char tabs, please call it a night.
    I don't understand what the problem is. Kennedy seems to mostly do Linux kernel programming. It is completely appropriate that he would adhere to the Linux kernel coding standards when doing kernel coding, don't you think?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #38
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,596
    Does no one use 3 spaces?
    2 is too few because everything looks more flush than it should. My code tends to have deep nests, and I abhor the horizontal scroll bar, so anything more is overboard. Like, 8. Seriously?
    I'll often use the tab key, but only if I've set the IDE to print 3 spaces instead.

    ...but what I do hate are source files that have been mangled up with a mixture of tabs and spaces.
    I've found that this is usually due to someone ripping someone else's code, or, because the same file was edited in different editors.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  9. #39
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    Quote Originally Posted by Yarin View Post
    Does no one use 3 spaces?
    I used 3 spaces for ten years then switched to 4 spaces for murky reasons.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  10. #40
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by brewbuck View Post
    I don't understand what the problem is. Kennedy seems to mostly do Linux kernel programming. It is completely appropriate that he would adhere to the Linux kernel coding standards when doing kernel coding, don't you think?
    Yes. I wasn't criticizing Kennedy, I was criticizing Mr. Torvalds. However, the part of the kernel source that I have looked at does seem to be mostly short functions and the nesting never gets past 3 or 4 levels, so maybe he is trying light the way down a certain path, I dunno.
    Last edited by MK27; 09-22-2009 at 07:12 PM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #41
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,596
    Quote Originally Posted by brewbuck View Post
    I used 3 spaces for ten years then switched to 4 spaces for murky reasons.
    Please, elaborate.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  12. #42
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Seriously, what do I use? I use everything. The whole point of styles is that you stay consistent with existing code.

    Single tab for work. Four spaces for Boost. Two spaces for Clang. I've even used the evil GNU indentation style when working on GCC (I still have nightmares about that). What am I supposed to do with this little single-choice poll?
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  13. #43
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,420
    Quote Originally Posted by Yarin View Post
    Does no one use 3 spaces?
    No! Non-power of 2 spaces are evil
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #44
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Tabs, with equivalent size of 3 spaces.
    I don't code crazy stuff like:
    Code:
    void Func(int X,
              int Y,
              int Z);
    ...so using tabs is of no problem for me.
    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.

  15. #45
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    3 spaces, since I'm hardcore. And using non-even indent levels seems to have it's advantages (I'll get back to you when I work out what they are ).

    Plus, for vim I highlight all the trailing spaces and hard tabs so I know if some tool has mixed them up. Yes amazing... For those of you who want to unlock my magic
    Code:
    set list listchars=tab:\|_,trail:.
    On a side note, who uses black backgrounds for their coding window? I find it's easier on my eyes.

    EDIT: I'm disappointed Linus has popped up in this thread too! What is it with him?
    Attached Images Attached Images  
    Last edited by zacs7; 09-23-2009 at 05:57 AM.

Page 3 of 4 FirstFirst 1234 LastLast
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-21-2008, 11:51 PM
  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, 01:07 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21