Indentation: Spaces or Tabs?

Get help with programming issues.

Moderator: PPS-Leaders

Post Reply
User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Indentation: Spaces or Tabs?

Post by beni » Wed Mar 04, 2009 4:59 pm

I want to ask you guys about indentation. As suggested in this paragraph we should use spaces instead of tabs. This is tradition in the development of Orxonox as this was suggested early by Patrick.

However I don't see the problem with tabs. In contrary actually I see some advantages when using tabs.
When indentation is done using tabs, everybody can configure his IDE such that the indentation looks like he likes it the most, since you can configure how much space a tab uses. When you use spaces instead, the image of the code is utterly constant.
Of course this is a advantage if you want the code to look like the same in every editor. On the other side each developer should be able to work with his own preferred indentation in my opinion, which he can configure if we would use tabs.

What do you think? Should we change our policy or are there disadvantages I did not happen to see?
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Thu Mar 05, 2009 7:41 am

I have a pretty strong opinion about that: Spaces.

The reason really is quite simple: Layout. For my part, when I'm coding, I sometimes make extensive use of spaces to format my codes, even on multiple lines. I especially like to align similar lines of code vertically.

That would get screwed by using tabs.

a few examples:

Code: Select all

      std::string timeString = "===============\n"
                               "time: " + std::string("x")
                             + "===============\n";
and from a header file:

Code: Select all

float                 timeFactor_;            //!< doc
bool                  bPaused_;               //!< doc
float                 timeFactorPauseBackup_; //!< doc
TclBind*              tclBind_;               //!< doc
TclThreadManager*     tclThreadManager_;      //!< doc
Shell*                shell_;                 //!< doc
LuaBind*              luaBind_;               //!< doc
It was written with 4 spaces/tab. Using tabs with a size of 4 on the creator machine, this would look like this on another machine with a tab size of 2:

Code: Select all

float        timeFactor_;      //!< docstring
bool        bPaused_;        //!< docstring
float        timeFactorPauseBackup_;  //!< docstring
TclBind*      tclBind_;        //!< docstring
TclThreadManager*  tclThreadManager_;    //!< docstring
Shell*        shell_;        //!< docstring
LuaBind*      luaBind_;        //!< docstring
Last edited by 1337 on Fri Mar 06, 2009 5:42 pm, edited 3 times in total.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
greenman
Baron Vladimir Harkonnen
Posts: 360
Joined: Wed Oct 03, 2007 2:53 pm
Contact:

Post by greenman » Fri Mar 06, 2009 4:16 pm

hm...

for me there are two points:
- if we would use tabs instead of spaces each coder could set his own tabsize (which is extremely practical if you have a 12" display) and there would be no discussion about 2/4 spaces of intendation. additionally it would be more consistent than now (now we have a mix of 2 and 4 spaces intendation)
- the con of using spaces is formatting as reto mentioned before

for me point 1 is more important than point 2

what about the others? x3n, felix, and everyone else ?
There are only 10 types of people in the world: Those who understand binary, and those who don't.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Post by x3n » Fri Mar 06, 2009 5:37 pm

/me likes spaces

And reto's reason is exactly the point. I use this kind of code formatting a lot.
Fabian 'x3n' Landau, Orxonox developer

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Fri Mar 06, 2009 5:48 pm

I agree that you could use tabs for the indentation only. But how do you tell your IDE to use spaces for the formatting instead?
And it would still screw my first example from the SignalHandler.

There is another argument I would like to post: If we were to switch now from spaces to tabs, it will result in major trouble:
- Editing existent code gives either ugly results or you'd have to switch to spaces every time.
- Converting ALL code to tabs is not an option because this is a major screw up in the SVN history. I still feel the aftermath of my svn:eol-style "native" intervention. It did resolve lots of issues, I'm sure, but it also screwed the SVN history.
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
BadElvis
Human Space Navy Lord Commander
Posts: 83
Joined: Wed Nov 14, 2007 1:07 pm
Contact:

Post by BadElvis » Mon Mar 09, 2009 11:57 am

I like spaces better, because I like nano, ms notepad, ascii-art, drawing with characters and formatting with whitespaces (that are not tabs).

But imo, we could also dictate to use tabs and to set 1 tab = 4 spaces. Then the code would look the same on every computer and we would only have to hit tab once instead of space 4 times.

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Mon Mar 09, 2009 12:23 pm

Hmm, I can actually hit tab once and get four spaces...
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
x3n
Baron Vladimir Harkonnen
Posts: 810
Joined: Mon Oct 30, 2006 5:40 pm
Contact:

Post by x3n » Tue Mar 10, 2009 4:57 pm

And that's the point where you should start liking better editors Felix :lol:
Fabian 'x3n' Landau, Orxonox developer

User avatar
Mozork
Mogthorgar, the mighty
Posts: 134
Joined: Wed Sep 24, 2008 3:27 pm

Post by Mozork » Tue Mar 10, 2009 7:41 pm

Hmm, I can actually hit tab once and get four spaces...
So can I, which means, that it really doesn't make any difference for me, as long the final solution is applied consistently (which could be a little problematic since all (or almost all?) code is formatted with spaces...)

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Tue Mar 10, 2009 7:51 pm

There should be really no tabs in our code except for the external libraries.
Mozork wrote: which could be a little problematic since all (or almost all?) code is formatted with spaces...
Why is that?
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
Mozork
Mogthorgar, the mighty
Posts: 134
Joined: Wed Sep 24, 2008 3:27 pm

Post by Mozork » Tue Mar 10, 2009 8:01 pm

If we were to revert to tabs we would have to convert all spaces (resp. 4 at a time) to tabs, which probably won't work as well as we'd hope to, so either we then go through all the files and verify, reps. correct or we risk that there are quite some inconsistencies/screwed up formatting. (Or so I'd expect...)

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Tue Mar 10, 2009 8:12 pm

Well, of course someone had to verify each file. Only the indentation should be changed, not the formatting.
But I guess the "tab group" wouldn't like to do just that :wink:
So my hopes are with a safe conclusion that nothing is going to change...
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

User avatar
beni
Baron Vladimir Harkonnen
Posts: 949
Joined: Tue Oct 03, 2006 9:15 am
Location: Zurich
Contact:

Post by beni » Tue Mar 10, 2009 9:52 pm

No, its really stupid. The only reason to change to tabs, is that everybody can individually modify the size of the tabs. However in most cases it would totally mess up the layout of the code, if people use different sizes for the tabs.

The example is already given by reto in his first post. This totally defies the benefit of having his own tabs, since the code just sucks.

Making a rule of telling everybody to use tabs = 4 spaces is stupid as well, because this again defies the benefit of being able to choose his own size for the tabs.

Easy example where using tabs would make sense:

Code: Select all

int x                   = 0;
int y                   = 0;
int z                   = 0;
and with 2 spaces per tab:
int x         = 0;
int y         = 0;
int z         = 0;
I mean.. that would be cool...

So I'm totally for spaces in the end. But I'm glad we discussed it and wasted time on this issue.
"I'm Commander Shepard and this is my favorite forum on the internet."

User avatar
greenman
Baron Vladimir Harkonnen
Posts: 360
Joined: Wed Oct 03, 2007 2:53 pm
Contact:

Post by greenman » Wed Mar 11, 2009 8:55 am

we could make a compromise, but I gess the effort would not be worth the result.
line beginings: use tabs (then each coder can choose his tabsize)
variable definitions: use spaces

then everybody would be glad and we wouldn't have ugly code
but it would be quite extensive to change all our existing code ^^
There are only 10 types of people in the world: Those who understand binary, and those who don't.

User avatar
1337
Baron Vladimir Harkonnen
Posts: 521
Joined: Wed Oct 10, 2007 7:59 am

Post by 1337 » Wed Mar 11, 2009 9:20 am

@Beni: Yeah, I see the benefits of your example. Unfortunately you can always give an almost identical example that doesn't use the same amounts of tabs for each of the lines because for instance the variable names are of different length. Then having different tab size would mess it up eventually.
But enough of this discussion...
http://www.xkcd.com/
A webcomic of romance, sarcasm, math, and language.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest