General / Off-Topic code indentation - tabs or spaces?

So we've just had our bi-monthly heated office argument about how to indent code.

It occured to me, does this ongoing debate range wider than our office?
I bet it does.

So, to start the ball rolling ..

I indent by 4 spaces, using tabs to represent 8 spaces.

So my code will go something like ..

int foo() {
<4 spaces>if (a) {
<tab>if (b) {
<tab><4 spaces>print("hello world");
<tab>}
<4 spaces>}
}

Anyone else?

Anyone from Frontier?
Do you have an in-house indentation policy or does everyone simply use the same IDE which does it for you so you actually don't have to know or care about this hotly debated and deeply important issue? (mixing indentation in the same source file is basically a sacking offence where we come from - either that or a round of drinks at the pub).

:p
 
I indent by 4 spaces, using tabs to represent 8 spaces.

stick to spaces or tabs but don't mix them.

i always preferred tabs. since online tools for code browsing became ubiquitous and multiplatform became a thing, spaces might actually be more convenient.

then again ... this discussion will never end! :D
 
Last edited:

Robert Maynard

Volunteer Moderator
Hehehe....

I've been writing StatusDisplay in C++ (MinGW 7.2 64-bit) using Code::Blocks as the IDE - and I use 4x spaces (or multiples thereof) for each and every indent. No tabs in my code - except for the one I keep handy to use when parsing Custom.3.0.binds, that is.

However this controversy pales compared to the position of curly-braces in code....
 

Ian Phillips

Volunteer Moderator
My basic rule of thumb (when I was still coding) was instilled into me by my team leader.

He insisted that any error had a clear and relevant message, together with the data that caused the exception. He told me that if it wasn't there and he was called at 03:00 AM the first thing he would be doing was calling me out of my bed to sort out the problem!

Following on from that, neat readable code was an obvious given. Indenting was used to aid the readability, not just because someone said code has to be indented.
 
Manual indentation is an idiotic remnant of the past that refuses to die, it should be purely an editor feature so everyone working on a particular piece of code can have it displayed to personal preference.
 
Having done coding in multiple languages in my former career, indentation and commenting were always used under the rule "You can never have too much, but too little can be near fatal when things go sideways at the end of a 30+ hour push"

For indents I always used spaces as they were platform/editor agnostic - just seemed to work out better that way...
 
Don't mix.
Try to use default editor settings.
Teams must use the same settings. Nothing worse than viewing change noises produced by using different settings, although most compare tools can ignore whitespace diffs.
Code is written to be read by humans, not computers.
 
So we've just had our bi-monthly heated office argument about how to indent code.

It occured to me, does this ongoing debate range wider than our office?
I bet it does.

So, to start the ball rolling ..

I indent by 4 spaces, using tabs to represent 8 spaces.

So my code will go something like ..

int foo() {
<4 spaces>if (a) {
<tab>if (b) {
<tab><4 spaces>print("hello world");
<tab>}
<4 spaces>}
}

Anyone else?

Anyone from Frontier?
Do you have an in-house indentation policy or does everyone simply use the same IDE which does it for you so you actually don't have to know or care about this hotly debated and deeply important issue? (mixing indentation in the same source file is basically a sacking offence where we come from - either that or a round of drinks at the pub).

:p

I have a vague recollection of a news article I read recently, apparently coders who use spaces earn 25% more on average.
 
The place I work - our coding guidelines say three spaces for indentation, no tabs. I don't even remember whether they said anything about where you should indent.

Platform (and editor) agnostic is the key here. By now, our code is done across at least four distinct companies (with a further one or two doing code reviews and metrics). Part of the people use Windows PCs, with or without a Linux VM, others run directly on Linux, and I don't know (or care) what the rest is using. And everyone uses an editor of their own choosing.
 
Over the course of my programming career, I worked for many different employers.

Some of them had strict coding standards with exact numbers of spaces or tabs. So of course I followed those as required.

When I worked for places that didn’t care, I used spaces ... usually four.

So yes the debate rages on and on. It’s much like these forums.
 
Manual indentation is an idiotic remnant of the past that refuses to die, it should be purely an editor feature so everyone working on a particular piece of code can have it displayed to personal preference.

Whaaaaa? You'l be telling me that vi is a remnant of the past next! Old skool rulez! :cool:
 
This is the kind of question that should be asked at job interviews just to add to the stress. What ever the answer the opposite is the correct one.

Companies I worked at started to outsource there work abroad so I'm available and ready to conform to any indentation policy.

[video=youtube;r76uQkMNhSA]https://www.youtube.com/watch?v=r76uQkMNhSA[/video]
 
In Code::Blocks you can make Tab generate four spaces this is what I use as it's much more readable. As for curly braces it K&R all the way :)
 
1. Replace tabs with spaces and use 3 spaces per tab indent
2. Markup old code with /* bug fix 123456 start of old code */ and /* bug fix 123456 end of old code */
3. Always comment out old code (never delete unless major version update)
4. Markup new code with /* bug fix 123456 start of new code */ and /* bug fix 123456 end of new code */
5. Identify bug fixes or enhancements in the file header information

Irrespective of language (VB exception for comment ') these rules have served me well over the days and even work well on Arduinos and PICs...
It used to be called a Coding Standard :)

/* bug fix 123abc start of old code */
/*
if( a=0 )
{
if( b=1 )
{
c=3;
}
}
*/
/* bug fix 123abc end of old code */

/* bug fix 123abc start of new code */
if( a=0 )
{
if( b=1 )
{
c=2;
}
}
/* bug fix 123abc end of new code */
 
Back
Top Bottom