StyleCop - Aarrgh
-
A rant, not a question. Is it just me, or is StyleCop designed to drive you insane. Just fired it up on a small project, so small that it consists only of Visual Studio templated classes/forms etc. Thousands of errors are flagged! . Use spaces not tabs (why? tabs are neater) . Put a space before and open bracket, or place the bracket on a new line (why? it makes my code look neater without the space for if statements etc. takes up less lines as well.) . Put using statements inside of namespaces not outside. ....and many more That last one is the worst. The reasoning is that you can put more than one namespace in the same file so using statements should be scoped to the namespace not the file. Sorry, but in that instance I would want to scope them to the file as well! Also, putting two namespaces in the same file will fail another stylecop rule thereby making this one redundant. Consistency of coding style across a company is good, but please Microsoft, make the rules make sense!
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
The Man from U.N.C.L.E. wrote:
That last one is the worst. The reasoning is that you can put more than one namespace in the same file so using statements should be scoped to the namespace not the file. Sorry, but in that instance I would want to scope them to the file as well! Also, putting two namespaces in the same file will fail another stylecop rule thereby making this one redundant.
Wow. If I remember rightly, they also have a rule about specifying only one class per file.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
The Man from U.N.C.L.E. wrote:
Use spaces not tabs (why? tabs are neater)
because tabs break this:
switch (foo)
{
case Bar: RunBar(); break;
case Foobar: RunFoo(); RunBar(); break;
}The Man from U.N.C.L.E. wrote:
Put a space before and open bracket, or place the bracket on a new line (why? it makes my code look neater without the space for if statements etc. takes up less lines as well.)
Because most coders, when growing up, migrate away from compactness and towards expressive structure.
The Man from U.N.C.L.E. wrote:
Put using statements inside of namespaces not outside.
Umm.... hrrrrr...... errr... You know that you can disable individual rules, don't you?
Agh! Reality! My Archnemesis![^]
| FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchyShouldn't that be
switch (foo)
{
case Foobar: RunFoo();
case Bar: RunBar(); break;
};instead. :)
Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra]
-
The Man from U.N.C.L.E. wrote:
Use spaces not tabs (why? tabs are neater)
because tabs break this:
switch (foo)
{
case Bar: RunBar(); break;
case Foobar: RunFoo(); RunBar(); break;
}The Man from U.N.C.L.E. wrote:
Put a space before and open bracket, or place the bracket on a new line (why? it makes my code look neater without the space for if statements etc. takes up less lines as well.)
Because most coders, when growing up, migrate away from compactness and towards expressive structure.
The Man from U.N.C.L.E. wrote:
Put using statements inside of namespaces not outside.
Umm.... hrrrrr...... errr... You know that you can disable individual rules, don't you?
Agh! Reality! My Archnemesis![^]
| FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchypeterchen wrote:
because tabs break this:
Not if you configure your IDE. Personally I prefer tabs because it's less keystrokes to navigate through.
Jeremy Falcon
-
The Man from U.N.C.L.E. wrote:
. Use spaces not tabs (why? tabs are neater)
I prefer spaces, when the code is developed with different editors on different platforms, spaces makes the code neater.
The Man from U.N.C.L.E. wrote:
. Put a space before and open bracket, or place the bracket on a new line
I agree with this. The "source code" should readable and not space saving. Also the stylecoding makes sure that different code writters follows the same coding pattern so that different part of the code does not look different.
Mr.Prakash wrote:
I prefer spaces, when the code is developed with different editors on different platforms, spaces makes the code neater.
But, realistically every IDE you'll use allows you to configure tab width.
Jeremy Falcon
-
Can you not suppress rules? FxCop allows you to do that.
Cheers, विक्रम (Got my troika of CCCs!) After all is said and done, much is said and little is done.
Vikram A Punathambekar wrote:
Can you not suppress rules? FxCop allows you to do that.
Yes you can. It even lets you specify new rules. It baffles me that people would download a free customizable app, refuse to customize it, and then complain about its default behavior in a public forum using their real name. :~
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
-
The Man from U.N.C.L.E. wrote:
That last one is the worst. The reasoning is that you can put more than one namespace in the same file so using statements should be scoped to the namespace not the file. Sorry, but in that instance I would want to scope them to the file as well! Also, putting two namespaces in the same file will fail another stylecop rule thereby making this one redundant.
Wow. If I remember rightly, they also have a rule about specifying only one class per file.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
Pete O'Hanlon wrote:
Wow. If I remember rightly, they also have a rule about specifying only one class per file.
Which is a good rule to follow in my opinion. I even use that for enums, even small ones.
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
-
The Man from U.N.C.L.E. wrote:
Use spaces not tabs (why? tabs are neater)
because tabs break this:
switch (foo)
{
case Bar: RunBar(); break;
case Foobar: RunFoo(); RunBar(); break;
}The Man from U.N.C.L.E. wrote:
Put a space before and open bracket, or place the bracket on a new line (why? it makes my code look neater without the space for if statements etc. takes up less lines as well.)
Because most coders, when growing up, migrate away from compactness and towards expressive structure.
The Man from U.N.C.L.E. wrote:
Put using statements inside of namespaces not outside.
Umm.... hrrrrr...... errr... You know that you can disable individual rules, don't you?
Agh! Reality! My Archnemesis![^]
| FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchyI know, I can disable rules but that rather defeats the point. I started from the point of how can I be expected to match the rules if the Visual Studio generated code itself does not. As to coding and brackets, I prefer, the following, though I know personal preference and all that.
switch (foo){
case Bar:
RunBar();
break;
case Foobar:
RunFoo();
RunBar();
break;
}In this example Style cop would prefer the following:
switch (foo)
{
case Bar:
RunBar();
break;
case Foobar:
RunFoo();
RunBar();
break;
}Who can really say which is more readable, though I would use spaces if pasting on CP because it is easier to type in the editor, that does not allow you to type tabs.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Pete O'Hanlon wrote:
Wow. If I remember rightly, they also have a rule about specifying only one class per file.
Which is a good rule to follow in my opinion. I even use that for enums, even small ones.
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
-
Vikram A Punathambekar wrote:
Can you not suppress rules? FxCop allows you to do that.
Yes you can. It even lets you specify new rules. It baffles me that people would download a free customizable app, refuse to customize it, and then complain about its default behavior in a public forum using their real name. :~
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
Got some interesting responses out of it though. MS does have some good explanations of the reasoning behind each rule, and clearly you have to chose the set for you as some rules don't sit well together. Customising the rules was the second thing I did. It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
-
Got some interesting responses out of it though. MS does have some good explanations of the reasoning behind each rule, and clearly you have to chose the set for you as some rules don't sit well together. Customising the rules was the second thing I did. It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
The Man from U.N.C.L.E. wrote:
It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.
Yeah I hear you there. The VS team seems to have been wholly unaware of the StyleCop guidelines :-) BTW, my real name jab was an attempted joke (since you are not using your real name at all)!
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
-
Pete O'Hanlon wrote:
Wow. If I remember rightly, they also have a rule about specifying only one class per file.
Which is a good rule to follow in my opinion. I even use that for enums, even small ones.
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
I follow that rule - and it clarifies why using statements are per namespace.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
Got some interesting responses out of it though. MS does have some good explanations of the reasoning behind each rule, and clearly you have to chose the set for you as some rules don't sit well together. Customising the rules was the second thing I did. It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
The Man from U.N.C.L.E. wrote:
You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.
Do what I say, not what I do.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads
-
Mr.Prakash wrote:
I prefer spaces, when the code is developed with different editors on different platforms, spaces makes the code neater.
But, realistically every IDE you'll use allows you to configure tab width.
Jeremy Falcon
Jeremy Falcon wrote:
But, realistically every IDE you'll use allows you to configure tab width.
Yes it does. the problem is not all spaces can be replaced with tabs while all tabs can be replaced with spaces. What I mean is, some people write it this way
enum something { <sp><sp><sp>Enum1, <tab> enum2 }
The above code will look different with different settings of tab. If you only have space then there is never a problem. I know I know you will say, why did enum1 had space in the first place. Some devs do it some intentionally and many times accidentally, instead of going after the dev on why he put sp instead of tab. It is easier to say replace all tabs with space. And consider this horrible patternenum something { <sp><sp><sp><tab>Enum1, <tab> enum2 }
With Tab setting to 4, they will look good, if not they will look bad. -
I know, I can disable rules but that rather defeats the point. I started from the point of how can I be expected to match the rules if the Visual Studio generated code itself does not. As to coding and brackets, I prefer, the following, though I know personal preference and all that.
switch (foo){
case Bar:
RunBar();
break;
case Foobar:
RunFoo();
RunBar();
break;
}In this example Style cop would prefer the following:
switch (foo)
{
case Bar:
RunBar();
break;
case Foobar:
RunFoo();
RunBar();
break;
}Who can really say which is more readable, though I would use spaces if pasting on CP because it is easier to type in the editor, that does not allow you to type tabs.
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]
There are other scenarios where "inner" tabs would break column alignment. Maybe elastic tabstops[^] would solve the debate (at least for me).
Agh! Reality! My Archnemesis![^]
| FoldWithUs! | sighist | WhoIncludes - Analyzing C++ include file hierarchy -
The Man from U.N.C.L.E. wrote:
It is however a bit depressing that creating a default windows forms app in VS 2010, with the default auto created main form, will give so many warnings with the default settings. Over a hundred. You would have thought that MS supplied templates would match the MS supplied style rules. Oh well.
Yeah I hear you there. The VS team seems to have been wholly unaware of the StyleCop guidelines :-) BTW, my real name jab was an attempted joke (since you are not using your real name at all)!
Regards, Nish
My technology blog: voidnish.wordpress.com (recently moved from web-host to wordpress)
Nishant Sivakumar wrote:
BTW, my real name jab was an attempted joke (since you are not using your real name at all)!
I am on my profile. Or am I? The life of a spy is never simple> :)
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]