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, 01:15 PM   #31
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 866
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.
Kennedy is offline   Reply With Quote
Old 09-22-2009, 01:22 PM   #32
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,754
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.
__________________
"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, 01:45 PM   #33
Code Goddess
 
Prelude's Avatar
 
Join Date: Sep 2001
Posts: 9,664
>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.
Prelude is offline   Reply With Quote
Old 09-22-2009, 02:06 PM   #34
Jaxom's & Imriel's Dad
 
Kennedy's Avatar
 
Join Date: Aug 2006
Location: Alabama
Posts: 866
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.
Kennedy is offline   Reply With Quote
Old 09-22-2009, 02:40 PM   #35
MENTAL DETECTOR
 
whiteflags's Avatar
 
Join Date: Apr 2006
Location: United States
Posts: 3,280
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.
__________________
<Niggawatts> Writing is both mechanical and organic
<Niggawatts> It's like a cyborg dragon.
<Niggawatts> Writing is like a cyborg dragon.
whiteflags is offline   Reply With Quote
Old 09-22-2009, 02:58 PM   #36
mastering the obvious
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,092
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.
__________________

"A man can't just sit around." -- Larry Walters

Last edited by MK27; 09-22-2009 at 03:09 PM.
MK27 is offline   Reply With Quote
Old 09-22-2009, 03:55 PM   #37
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,754
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?
__________________
"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, 06:35 PM   #38
Unregistered User
 
Yarin's Avatar
 
Join Date: Jul 2007
Posts: 980
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.

Quote:
...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.
__________________
May the Source be with you.
Yarin is offline   Reply With Quote
Old 09-22-2009, 06:44 PM   #39
Senior software engineer
 
brewbuck's Avatar
 
Join Date: Mar 2007
Location: Portland, OR
Posts: 5,754
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.
__________________
"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, 07:09 PM   #40
mastering the obvious
 
MK27's Avatar
 
Join Date: Jul 2008
Location: SE Queens
Posts: 5,092
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.
__________________

"A man can't just sit around." -- Larry Walters

Last edited by MK27; 09-22-2009 at 07:12 PM.
MK27 is offline   Reply With Quote
Old 09-22-2009, 09:46 PM   #41
Unregistered User
 
Yarin's Avatar
 
Join Date: Jul 2007
Posts: 980
Quote:
Originally Posted by brewbuck View Post
I used 3 spaces for ten years then switched to 4 spaces for murky reasons.
Please, elaborate.
__________________
May the Source be with you.
Yarin is offline   Reply With Quote
Old 09-23-2009, 03:23 AM   #42
Cat without Hat
 
CornedBee's Avatar
 
Join Date: Apr 2003
Posts: 8,492
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
CornedBee is offline   Reply With Quote
Old 09-23-2009, 03:56 AM   #43
Mysterious C++ User
 
Elysia's Avatar
 
Join Date: Oct 2007
Posts: 14,767
Quote:
Originally Posted by Yarin View Post
Does no one use 3 spaces?
No! Non-power of 2 spaces are evil
__________________
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-23-2009, 04:38 AM   #44
Confused
 
Magos's Avatar
 
Join Date: Sep 2001
Location: Sweden
Posts: 3,125
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.
Magos is offline   Reply With Quote
Old 09-23-2009, 05:50 AM   #45
Woof, woof!
 
zacs7's Avatar
 
Join Date: Mar 2007
Location: Australia
Posts: 3,288
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
 
__________________
"I.T. gets the chicky-babes" - M. Kelly
bakefile | vim

Last edited by zacs7; 09-23-2009 at 05:57 AM.
zacs7 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 04:00 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