C Board  

Go Back   C Board > Community Boards > General Discussions

View Poll Results: How do you indent?
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%
Voters: 34. You may not vote on this poll

Reply
 
LinkBack Thread Tools Display Modes
Old 09-22-2009, 11:44 AM   #16
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,754
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.
__________________
"Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot
brewbuck is offline   Reply With Quote
Old 09-22-2009, 11:51 AM   #17
Robot
 
Join Date: Mar 2009
Posts: 258
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?
Memloop is offline   Reply With Quote
Old 09-22-2009, 11:53 AM   #18
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,732
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.
Thantos is offline   Reply With Quote
Old 09-22-2009, 11:53 AM   #19
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 5,018
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.
Sebastiani is offline   Reply With Quote
Old 09-22-2009, 12:01 PM   #20
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,664
>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.
Prelude is offline   Reply With Quote
Old 09-22-2009, 12:08 PM   #21
Registered User
 
Join Date: Dec 2006
Location: Canada
Posts: 2,001
I use 8 spaces (set my editor to convert tabs to spaces). No particular reason.
cyberfish is offline   Reply With Quote
Old 09-22-2009, 12:33 PM   #22
(?<!re)tired
 
Mario F.'s Avatar
 
Join Date: May 2006
Location: Portugal
Posts: 5,611
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.


Mario F. is offline   Reply With Quote
Old 09-22-2009, 12:41 PM   #23
l'Anziano
 
DavidP's Avatar
 
Join Date: Aug 2001
Posts: 2,616
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."
DavidP is offline   Reply With Quote
Old 09-22-2009, 12:45 PM   #24
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 11,263
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.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 09-22-2009, 12:49 PM   #25
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 3,020
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.
bithub is offline   Reply With Quote
Old 09-22-2009, 12:52 PM   #26
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,664
>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.
Prelude is offline   Reply With Quote
Old 09-22-2009, 12:58 PM   #27
Robot
 
Join Date: Mar 2009
Posts: 258
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.
Memloop is offline   Reply With Quote
Old 09-22-2009, 01:02 PM   #28
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,767
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.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Old 09-22-2009, 01:10 PM   #29
C++ Witch
 
laserlight's Avatar
 
Join Date: Oct 2003
Location: Singapore
Posts: 11,263
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.
__________________
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar

Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
laserlight is offline   Reply With Quote
Old 09-22-2009, 01:14 PM   #30
Guest
 
Sebastiani's Avatar
 
Join Date: Aug 2001
Posts: 5,018
Quote:
Originally Posted by Mario F. View Post
So tabs are evil because of broken editors and programmer misuse? Ignoratio elenchi.
Sebastiani is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing 3 spaces to tabs dnguyen1022 C Programming 2 12-22-2008 12:51 AM
Tabs or Spaces DavidP General Discussions 46 04-08-2007 11:45 AM
Visual C++ Golffor1 C++ Programming 1 08-04-2003 04:30 PM
tabs to spaces with dev c++ v.4 stallion Windows Programming 2 01-28-2003 02:07 PM
Tab Controls - API -KEN- Windows Programming 7 06-02-2002 09:44 AM


All times are GMT -6. The time now is 03:56 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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