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. #16
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    I use tabs at work. The reason is that some people like a larger visual indent and some people prefer a smaller one. By using tabs, you can adjust this by changing your editor's tab width.

    For non-work, I indent with 4 spaces. I don't really have a strong feeling about it, but what I do hate are source files that have been mangled up with a mixture of tabs and spaces.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  2. #17
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    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?

  3. #18
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Quote Originally Posted by brewbuck View Post
    I use tabs at work. The reason is that some people like a larger visual indent and some people prefer a smaller one. By using tabs, you can adjust this by changing your editor's tab width.

    For non-work, I indent with 4 spaces. I don't really have a strong feeling about it, but what I do hate are source files that have been mangled up with a mixture of tabs and spaces.
    So true. I can use either tabs or spaces but it absolutely sucks when someone uses both.

    I personally use tabs as it makes doing find/replace regex a lot easier, plus hitting the tab key is easier than hitting the space bar a bunch of times. Though with a good text editor you don't have to worry so much about that as it takes care of it for ya.

  4. #19
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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?
    Tell 'em to turn on line wrapping and deal with it.

  5. #20
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >It would allow us to see how everyone slowly trends from their
    >imperfect indentation style, to the correct style of 4 spaces over time

    Heheh.

    >I was just wondering: how do you indent your source code?
    I prefer two spaces, but any even number is comfortable. Odd numbers are unnatural.
    My best code is written with the delete key.

  6. #21
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    I use 8 spaces (set my editor to convert tabs to spaces). No particular reason.

  7. #22
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    This pool has become a revelation to me. I was pretty sure until now very few people used ASCII(9) for their code indenting. And I certainly haven't been seeing much of that when looking at code online or when copy pasting it to my editor from many different sources.

    My guess... this pool is fixed!

    tabs are evil.
    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.

  8. #23
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,743
    I most definitely use ASCII(9), a.k.a. '\t'. It's the best way to go to keep things properly aligned, in my opinion. I hate it when I edit code that uses spaces and I have to backspace a million times to delete an indentation instead of simply backspacing once.
    My Website

    "Circular logic is good because it is."

  9. #24
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by DavidP
    I hate it when I edit code that uses spaces and I have to backspace a million times to delete an indentation instead of simply backspacing once.
    Depending on your editor and its configuration, you may only need to backspace once, or to use something like shift + tab.

    Anyway, I note that this thread is about the amount by which one indents, not about whether one indents with space characters or tab characters.
    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

  10. #25
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Quote Originally Posted by DavidP View Post
    I most definitely use ASCII(9), a.k.a. '\t'. It's the best way to go to keep things properly aligned, in my opinion. I hate it when I edit code that uses spaces and I have to backspace a million times to delete an indentation instead of simply backspacing once.
    With vi, I use:
    :set tabstop=4
    :set shiftwidth=4
    :set expandtab
    :set softtabstop=4

    With these settings, you don't even know you are using spaces instead of tabs. The tab key, delete key, and formatting behave exactly as you would expect. Plus you get the added benefit of consistent formatting since you are actually using spaces instead of tabs.

    There is probably equivalent settings in other editors, but why would anyone ever want to use a different editor?
    bit∙hub [bit-huhb] n. A source and destination for information.

  11. #26
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >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.
    My best code is written with the delete key.

  12. #27
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Quote Originally Posted by Sebastiani View Post
    Tell 'em to turn on line wrapping and deal with it.
    I guess this situation should never happen since any company that has a policy that code should be at most 80 characters wide, will most likely also specify how long the indentation width should be.

  13. #28
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Me, I like tabs. Usually I think that 4 spaces is an ideal indentation level, and it is the default of Visual Studio, so that is what I use.
    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. #29
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by Prelude
    The amount is far more interesting.
    Aye, but I see that either I missed the ": spaces or tabs", or EVOEx has changed the topic.
    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
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Mario F. View Post
    So tabs are evil because of broken editors and programmer misuse? Ignoratio elenchi.

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