Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Indentation (4 spaces vs 8 spaces)

This thread is locked; no one can reply to it. rss feed Print
Indentation (4 spaces vs 8 spaces)
decepto
Member #7,102
April 2006
avatar

A couple questions:

1. Do you use hard tabs or soft spaces for indentation - and why?
2. How many spaces do you indent in? 4, 8 or (gasp!) 2?

Personally, I use soft spaces with an indent of 4 for every programming language. Trying to use 8 space indentation is just too hard when I try to keep my lines less than 80 characters.

--------------------------------------------------
Boom!

Sol Blast
Member #9,655
April 2008
avatar

I prefer the uniformity you get with the tab key (so in other words 4 in MVS6).

ITAmember
Member #10,095
August 2008

I use soft indentation and 4 spaces because I'm a big python programmer and that is the python standard. But that's just me.

Jeff Bernard
Member #6,698
December 2005
avatar

I typically use hard tabs. But if I ever use soft spacing (such as when formatting code for a forum), I use 3 spaces.

--
I thought I was wrong once, but I was mistaken.

CosmicR
Member #6,889
February 2006
avatar

I use whatever the source code formatter does in code::blocks. I think it's the K & R standard.
Previously before I had the formatter I used spaces, often only 2 because sometimes lines got too long when I used descriptive variable names.

OnlineCop
Member #7,919
October 2006
avatar

I use tabs to indent, and spaces to align.

My IDE usually have the tab/indentation level set to 3, since it's not as space-wasting as 4, and easier to read than 2.

Although people who use tabs to indent also use tabs to align, I think it's a pain to visually match everything in their sources by either changing my IDE's tab/indentation level to match theirs or (in the extreme case) reformat their code to make everything align correctly.

--|--|std::cout << "Text that is so long that it needs to break across lines "
--|--|          << "have the tabs set the same as the line above, and then hit "
--|--|          << "SPACE until the <<'s are aligned visually.";

Now, whether I choose to have my tabs/indentation set at 3,4,8, or some other value, everything shifts by the same proportions and no reindentation is needed.

MiquelFire
Member #3,110
January 2003
avatar

I use tabs. Mainly so that if I edit the file in an editor that doesn't use Shift+Tab to deindent (or doesn't auto indent) I have less keys to type.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

CGamesPlay
Member #2,559
July 2002
avatar

Iusetabsbecausemykeyboarddoesn'thaveaspacebar.

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I use the tab key to put in spaces up to the next tab stop using Code Blocks. 3 space indentation is just about perfect. Not too much extra space on the left with large indentation levels, and enough space to see at a quick glance which blocks are where.

I can't stand actual tabs though, because Code Blocks insists on displaying them as arrows, which makes any code with actual tabs in it look awful, at which point I immediately replace them with spaces. I may put in a request on the Code Blocks forums to have them allow invisible tabs as an option one of these days.

What bugs me the most is when people use an 8 space tab with a different indentation level, so there's one tab and a space to meet up with the 3rd 3 space indentation.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

I can't stand actual tabs though, because Code Blocks insists on displaying them as arrows

Huh? Why don't you set the Settings->Editor->General Settings->Indent Options->Show Spaces to 'No'?

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Quote:

Huh? Why don't you set the Settings->Editor->General Settings->Indent Options->Show Spaces to 'No'?

Yikes! That made my code all floaty! I like having the dots indicate the spaces, but not the arrows indicating tabs. And besides, I didn't think that turning 'Show Spaces' off would turn off the tab characters as well. I learned something new. Thanks. :)

Evert
Member #794
November 2000
avatar

Soft tabs (in other words, tab inserts spaces), with a tabsize of 3.

SiegeLord
Member #7,827
October 2006
avatar

Quote:

I like having the dots indicate the spaces, but not the arrows indicating tabs

Yeah, I guess they could have picked something less visually striking than an arrow... heh.

As for the OP: I use tabs (tab size 4), because I like them. Also, makes keyboard navigation easier for me. I've yet to see an editor that will respect indentation when moving using the arrow keys unless you use tabs.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Mokkan
Member #4,355
February 2004
avatar

I use four spaces, no tabs. I can't stand tabs.

someone972
Member #7,719
August 2006
avatar

I use four soft spaces. This is either done by CB when I press tab or when I do it myself. I'm not sure which one I use more because I haven't been paying attention.

______________________________________
As long as it remains classified how long it took me to make I'll be deemed a computer game genius. - William Labbett
Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why. -Unknown
I have recklessly set in motion a chain of events with the potential to so-drastically change the path of my life that I can only find it to be beautifully frightening.

Neil Black
Member #7,867
October 2006
avatar

I use whatever the environment I'm in defaults to, because I'm too lazy to go in a change a setting that looks and works fine by default. I've used Dev-Cpp for years and I'm still not sure what the default setting is.

If I had to pick a setting I'd go with four spaces.

Timorg
Member #2,028
March 2002

In Code::Blocks I used to use 4 spaces with a tab, and save them as a tab character, but I reinstalled at some point and forgot to change the setting. So I use 4 spaces, but use two for case labels and public/private/protected in classes.

Eg.

1class USELESS
2{
3 public:
4 void funct(int a)
5 {
6 switch (a)
7 {
8 case 1:
9 printf("the number was one\n");
10 break;
11 case 2:
12 printf("the number was two\n");
13 break;
14 default:
15 printf("the number wasn't one or two\n");
16 break;
17 }
18 }
19};

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

Trezker
Member #1,739
December 2001
avatar

I prefer tabs. But if I have to use spaces, 2 is enough.

bamccaig
Member #7,536
July 2006
avatar

I use tabs to indent, but spaces to align (i.e., multiline statements that don't line up with tabs). My tab size is always 4. I find tabs more easy to work with, but spaces are needed to align continued lines where tabs don't necessarily line up perfectly. I find 4 spaces to be the most comfortable size.

Jonatan Hedborg
Member #4,886
July 2004
avatar

Always tabs. Spaces are evil. Tab size 2 or 3 is enough.

HardTranceFan
Member #7,317
June 2006
avatar

2 spaces. Any more and the nesting starts to slide off the side of the screen.

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Onewing
Member #6,152
August 2005
avatar

I use the '>' symbol as to know that I'm moving my characters to the right. Unfortunately, I had to build my own compiler to accomplish this. :-/

------------
Solo-Games.org | My Tech Blog: The Digital Helm

Steve++
Member #1,816
January 2002

Four spaces using hard tabs seems to be a common default for C-based languages. Why fight it?

Jonatan Hedborg
Member #4,886
July 2004
avatar

Because if you use hard tabs you can fight it without anyone else noticing ;)

Neil Walker
Member #210
April 2000
avatar

I really couldn't care less, I take whatever the default is for TAB, it's only spacing.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie



Go to: