views:

2040

answers:

7

For C# Visual Studio uses 4 spaces by default, whereas for C++ it is hard-tabs. Why is it so? Why is it different?

My project consists of both C# and C++ code and the difference really annoys me. I want to set a common standard for all the sources, but I wonder if this would have any drawbacks.

+3  A: 

If you're looking for a completely logical, well reasoned justification for this difference I don't think you'll find one. Despite the many flame wars around tabs vs spaces there really isn't a real winner (otherwise the war would be over).

The way to get around this is via a .vssettings file. When I first started with VS 2005, I set the tabs/spaces default in each language. You can do this via Tools -> Options -> Text Editor -> (C#/C++). Then I export the tab settings into a .vsssettings file. Whenever I install VS on a new machine I just import that file and I have my happy space/tab settings.

PS: spaces rule :)

JaredPar
You can change these settings directly in tools->options as well. But the .vssettings thing does seem handy for taking the settings with you when working on a different machine
jalf
+1  A: 

I doubt there are any drawbacks as C++ grammar doesn't distinguish between tabs and spaces. By the way, I think the best way to set code style standards is to export VS settings and share it with the team.

Mehrdad Afshari
I don't believe the C# grammar distinguishes as well. I *think* the only language which does have a distinction is F# which prefers spaces.
JaredPar
Nope. C# grammar doesn't distinguish either. There are plenty of high level languages out there, so many of them probably distinguish spaces and tabs: http://en.wikipedia.org/wiki/Whitespace_(programming_language)
Mehrdad Afshari
I'm sure there are. IIRC python distinguishes whitespace but I'm not sure if it cares tab/spaces or not.
JaredPar
SO corrupted the link: http://en.wikipedia.org/wiki/Whitespace_programming_language
Mehrdad Afshari
A: 

The reason behind C#'s default 4 spaces is that whoever will open the file the indentation will be the same.

You are free to change it as you like in preferences.

Jozef Izso
A: 

For C# Visual Studio uses 4 spaces by default, whereas for C++ it is hard-tabs. Why is it so?

Why not?

Just change it if you're not happy.

Gary Willoughby
That's so far from an answer, I'm not sure why you posted this.
TheSoftwareJedi
Well, why not? the tabs v spaces argument is never going to end so why shouldn't the two languages have different defaults? They were probably worked on by teams with different whitespace religions? Honestly, just change it if you're not happy, it's not hard.
Gary Willoughby
A: 

Just go with whatever you prefer, I normally use tabs in C++. Those who view my code all use the default VS settings RE tabs anyway so there is no real pull to replace that with spaces. I'm not sure what its like now but when F# was in its infancy (i.e., pretty early release out of MSR) you needed to use spaces in #light code otherwise the compiler would complain as whitespace was important.

Different people have different preferences, I know some who religiously use spaces, on the other hand I know more that uses tabs.

Granville Barnett
A: 

Spaces make it more difficult to navigate through code with the keyboard.

With spaces, most people will use four spaces, but some will use two or three. With tabs, the people who want their code tabbed out with two spaces can simply set the tab character to display as wide as two spaces, and the coding style remains consistent.

If you're using spaces for tabs in any HTML, CSS, or JavaScript, you're doing it wrong. There's no tabs-vs-spaces debate for html/css/js - it's either tabs, or ignorance. Client-side code is not compiled, and IIS doesn't have compression turned on by default - excess white space = excess fat.

Way back when, VB6 didn't give us the choice to use tabs, but now we can and should - if you don't, your code makes it look like you're still clinging to old-school ways.

So stop coding like it's 1999. Use tabs. Do it for the children.

Fizgig
I'm sorry? This is a personal preference. I *do* prefer tabs, actually. But don't flame it.
Camilo Martin
A: 

Of course tabs is the only right way. Tab can do everything spaces can do. Spaces cannot do much of what tab can do.

Tabs allow easy change of indentation and easy navigation without having to press arrow keys too many times, and would having to hold control.

The real solution is to have the editor be able to navigate and tab indented file as if it was space indented, if the user prefers so. The file would be saved with tabs. Very simple and accommodating everybody.

The problem in c# 2010 is that I cannot find any option to change it to tabs.

Pete
Obviously you are still using sub-optimal text editing paradigm :P In VS they have ViEmu.
kizzx2