|
-
April 13th, 2010, 12:55 AM
#1
Change stupid indent style
Visual Studio (2005) automatically indents braces for each case in switch statements in what I consider to be the most impossibly idiotic manner. I have always ignored it and fixed it manually but now I'm sick of it and want to know if anyone knows of a way of changing this behaviour - I can't find any options in the formatting area.
-
April 13th, 2010, 07:29 AM
#2
Re: Change stupid indent style
VS 2008 has an option to disable "Indent braces" under Tools/Options/Text Editor/C++/Formatting. I don't remember if 2005 has the equivalent.
Gort...Klaatu, Barada Nikto!
-
April 15th, 2010, 12:11 AM
#3
Re: Change stupid indent style
Thanks Mike. Yes 2005 has that option - I have it unchecked, but it doesn't seem to govern the bracing in switches.
I just don't know where VS got this indent style from and why it only applies it to switches. I've tried to learn to live with it and get used to it. I figured that after a while I would grow to love this style and wonder why I ever did it differently. But I can't. It's just too stupid.
-
April 15th, 2010, 07:34 AM
#4
Re: Change stupid indent style
The fact that "case" and "break" in a switch statement have no requirement for being delimited by curly braces makes formatting a switch statement somewhat suggestive, but I'm curious what it is you find so annoying about VS's handling of this. How do you format your switch statements? VS's handling is consistent with they way I've always done it (since years before MS even thought of VS).
-
April 15th, 2010, 04:35 PM
#5
Re: Change stupid indent style
There are times where bracing in case branches is necessary such as the following. Case 1 is how I like to format my braces. Case 2 is how Visual studio lays it out. I find the second way much harder to read.
Code:
void MyApp::Command(int id, void* pData)
{
switch (id) {
// the way I format it
case MSGID_SOMETHING: {
MyObj* pObj = (MyObj*) pData;
SomeFunc(pObj);
break;
}
// the way VS formats it
case MSGID_SOMETHINGELSE: {
MyObj* pObj = (MyObj*) pData;
SomeOtherFunc(pObj);
break;
}
}
}
-
April 15th, 2010, 08:29 PM
#6
Re: Change stupid indent style
Indeed. I don't recall the last time I ever used braces in a case before.
-
April 16th, 2010, 07:07 PM
#7
Re: Change stupid indent style
Maybe I'll amaze you, but I think the VS uses the braces I the right way. The way you use them looks to me very confusing, althoug I have to admit many people do the same.
Your second case looks indeed very ugly, but it's your fault, not the VS's fault. You don't understand a simple fact, the braces are vertically alligned. Try to move the first brace to the next line and everything will turn to look very nice:
Code:
case MSGID_SOMETHING:
{
MyObj* pObj = (MyObj*) pData;
SomeFunc(pObj);
break;
}
To me it's crystal clear where the braces open, where they close, and which brace is the pair of the other. Don't you think the same ?
-
April 16th, 2010, 07:17 PM
#8
Re: Change stupid indent style
 Originally Posted by srelu
Maybe I'll amaze you, but I think the VS uses the braces I the right way. The way you use them looks to me very confusing, althoug I have to admit many people do the same.
Your second case looks indeed very ugly, but it's your fault, not the VS's fault. You don't understand a simple fact, the braces are vertically alligned. Try to move the first brace to the next line and everything will turn to look very nice:
Code:
case MSGID_SOMETHING:
{
MyObj* pObj = (MyObj*) pData;
SomeFunc(pObj);
break;
}
To me it's crystal clear where the braces open, where they close, and which brace is the pair of the other. Don't you think the same ?
I see a lot of
in GNU applications. This format has always bothered me. I guess they think saving one line is better than having braces match up.
-
April 16th, 2010, 09:57 PM
#9
Re: Change stupid indent style
...I'm sick of it and want to know if anyone knows of a way of changing this behaviour...
It should cease if in Tools -> Options, Text Editor -> C/C++ -> Tabs, you set "Indenting" to "None", but you'll probably end up puting this back to it's current setting when you see what else you lose.
Can I pitch in on the rest of the discussion?
[soapbox]
Mandated coding standards are a pet peeve to which I'm signficantly opposed.
Everyone has an opinion which is no less valid than that of those around him or her. The mistake, IMO, is in deciding that writing code is not partly an artform and that one opinion is to be exalted above all others. Why would someone encourage their mind to be so inflexible as to be unable to read code unless it is has a particular format? We are humans, not the machines we program.
Some of the older code where I work has three to four different coding styles within the same file, depending on the tastes of the person who was working in it at any particular time. It's not a problem once you choose to not be bothered by it.
[/soapbox]
-
April 17th, 2010, 06:01 AM
#10
Re: Change stupid indent style
In fact, I don't see any reason for such a buzz around the brace style. Some people consider something ugly while the others love that same much. Some adopt coding standards where brace style is explained explicitly and very strictly, but they are apparently ready to pay for that whim. Others are quite tolerant to this style point as well as to grunting of particular teammates. Man is a creature that can stand almost any torture. If he wills, of course.
Best regards,
Igor
-
April 17th, 2010, 05:57 PM
#11
Re: Change stupid indent style
Agree here Igor. Since I'm originally a Pascal programmer (at least I think that's the reason) I preferred bracing likebut things do change so now I useAfter all it's better to do it like everybody else do it since that makes reading of other peoples code easier.
Having said that I have to agree that I don't wan't my brace placed líke that in a switch. If there's reason for braces in a switch I prefer it like
Code:
switch (id)
{
case MSGID_SOMETHING:
{
...
}
break;
}
Last edited by S_M_A; April 18th, 2010 at 03:26 PM.
-
April 18th, 2010, 04:25 AM
#12
Re: Change stupid indent style
 Originally Posted by GeoRanger
Some of the older code where I work has three to four different coding styles within the same file, depending on the tastes of the person who was working in it at any particular time. It's not a problem once you choose to not be bothered by it.
Which is exactly why coding standards exist. The point is not that one style is better than all others in every aspect, but that mixing styles is always worse than consistently using one style (no matter which one).
Cheers, D Drmmr
Please put [code][/code] tags around your code to preserve indentation and make it more readable.
As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|