PDA

View Full Version : How far do you indent?



dwks
08-30-2005, 12:25 PM
Okay, just curious again: How many spaces do you indent? I indent 4 spaces. I think 4 will be the majority.

7smurfs
08-30-2005, 12:26 PM
Tab.

Stoned_Coder
08-30-2005, 12:27 PM
never tab unless you have tabs set to insert spaces.

dwks
08-30-2005, 12:28 PM
Well, how much does the tab indent in your editor?

dwks
08-30-2005, 12:31 PM
never tab unless you have tabs set to insert spaces.
You know, I agree. Tabs can really mess up your indentation. But everyone seems to use them.

linkofazeroth
08-30-2005, 12:47 PM
I let Dev-C++ indent for me, unless an if statement indents too far, then I set it to about 7. Otherwise, it's 4 or 5. So I selected all three options above. :p

anonytmouse
08-30-2005, 01:07 PM
never tab unless you have tabs set to insert spaces.

If you can manage not to mix the two, tabs are fine. 2 or 3 spaces are not enough. Use 4 or more.

dwks
08-30-2005, 01:13 PM
You guys are weird. I ALWAYS indent 4 spaces.

Narf
08-30-2005, 01:14 PM
2 or 3 spaces are not enough. Use 4 or more.
My experience doesn't justify this statement. In my opinion, 1 is too little, but 2 is enough if the code is formatted consistently. 4 can easily be too much with some styles of C and most styles of C++ where lines can get pretty long, and the indention doesn't help.

dwks
08-30-2005, 01:16 PM
Does anyone actually indent 1 space?

I know Govtcheez voted for everything, but I doubt he uses 1 space. Well, maybe.

Boomba
08-30-2005, 01:24 PM
I do a tab, whyd does a tab screw things up?

dwks
08-30-2005, 01:26 PM
Well, if you transfer it, it sometimes ends up looking like this:



int main(void) {
if(1) {
printf("hi");
}
return 0;
}

alphaoide
08-30-2005, 01:37 PM
Yup. I use 2. 4 is too much; especially if you have to keep it under 80 char per line, those indents add up quickly.

dwks
08-30-2005, 01:41 PM
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.

Rashakil Fol
08-30-2005, 03:55 PM
If your lines are too long it's not the tab size that is the problem.

Narf
08-30-2005, 04:11 PM
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. ;)

Govtcheez
08-30-2005, 04:53 PM
voted everything

Queatrix
08-30-2005, 05:19 PM
When you tab in Dev-C++, it puts multipule spaces according to the line above or below the line you are tabing. (I tab.)

valis
08-30-2005, 05:27 PM
I use tab, with any modern editor you can setup so much tab stuff it allows one to have their own spacing style.

nickname_changed
08-30-2005, 06:10 PM
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.

Zach L.
08-30-2005, 06:11 PM
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.

cboard_member
09-01-2005, 12:33 PM
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.

Magos
09-01-2005, 01:04 PM
Well, if you transfer it, it sometimes ends up looking like this:



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.

adrianxw
09-01-2005, 02:34 PM
Coding standards at your house will decide. Left to me 4 spaces.

^xor
09-02-2005, 09:31 AM
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.

:set paste

cboard_member
09-02-2005, 10:37 AM
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.

:set paste

Thanks for the VIM tip, I can never get it to past right :)

Rez
09-02-2005, 01:26 PM
2 for C and C++ and Perl and Java and HTML, 4 for Visual Basic. hehe.

swoopy
09-03-2005, 12:08 AM
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.

laserlight
09-03-2005, 02:17 AM
4 spaces, though with a tab.

I find using an odd number of spaces odd, for some reason.

prog-bman
09-03-2005, 02:20 AM
4. Just typing this

jverkoey
09-03-2005, 02:23 AM
I use a varying number of spaces depending on the language I'm working with...php my spacing is very sporadic because my editor replaces all tabs with spaces automatically so it's hard to have some uniform spacing thing going on (as the auto-tab-indentation-selector-thing isn't very good, it'll randomly indent 2 spaces, or maybe 4, or maybe 7).

C++, however, I use 4 all the time, just seems like a decent in-between as I don't think 2 would make the code incredibly readable but 6 or 8 would make the code harder to read. In the end, I doubt I'll run out of hard drive space by using 4 spaces to indent as opposed to 2 or 1, heh, these days you can buy a gig of hard drive space for $1.

Jaqui
09-03-2005, 07:41 AM
I start at left margin and add 2 per level of indentation.

I've never needed to go deeper than 6 that way.

Ancient Dragon
09-03-2005, 08:31 PM
I use tabs where each tab is 5 spaces. Never noticed the problem like drks posted example.

sethjackson
09-17-2005, 04:36 PM
I use 4 spaces. In Code:Blocks a Tab is 4 spaces so I use that too. ;)