tags:

views:

261

answers:

6

A recent question about StyleCop alerted me to the use of tools to enforce coding style. I would feel very annoyed if I were required to run one of these tools while I was developing. Do people really find them useful? Why or why not?

Everyone that has answered so far has indicated that they think that style/formatting rules are useful, and I am in 100% agreement with that. But what about using a tool for enforcement, rather than a style guide and regular code reviews? Have people found that useful in practice? Why or why not?

A: 

If style refers to formatting (like '{' must be at the end or at the beginning of a line), it can be very annoying, especially if merges are involves and if that style is not strictly enforced for all developers.

If style refers to 'good practice" (like the body of a 'if' statement must be wrapped in opening and closing curly brackets), it can be actually very useful.

VonC
A: 

I think in a large team, a uniform coding style is essential. Having some standard helps with maintainability, in that a new developer can be brought on to maintain old code, with minimal learning curve.

As far as enforcing styling differences (such as where the '{' comes) can be very easily be accomplished by automated tools, without imposing on the development process too much. Eclipse and Visual Studio both have a very rich set of options to format your code automatically based on a large set of options.

Scott Wegner
+2  A: 

Yes, it's very helpful - particularly in large projects. It means you can go to anyone else's code, and it won't look alien to you. This means that people are more portable across projects, which gives a lot more flexibility - both for the person and the company.

The downside is that a lot of time can be spent arguing over which style to use.

Jon Skeet
A: 

Restrictions on programming or formatting style might help reducing friction in a team of more than one person.

Restrictions on language features (especially using only a subset of C#) can help you concentrate on the problem domain instead of having to deal with an overwhelming number of concepts. This does matter if your software has to be robust and thoroughly understandable.

Regards, tamberg

tamberg
+1  A: 

There is a difference between a Coding style and a Formatting style. A coding style enforces good practices. the body of a 'IF' statement must be wrapped in opening and closing curly brackets A formatting style is how the code looks. where the '{' comes in an 'IF' statement.

In a team environment;

a good formatting tool will allow all the developers to see the code the way they want to see the code. a good style tool will insure all the code follows the same guidelines

That is a thin line. In my book, the location of the curly bracket is more important than the presence of curly brackets at all.
Dave Van den Eynde
+1  A: 

I like the concept of StyleCop, although I don't really care for a lot of the rules. Style is just so subjective that I find myself struggling to firmly decide if it should be part of our process or not. I really would prefer to see the team with a unified style, though, which is why I am so torn.

Obviously, the flip-side of the equation, with a tool like FxCop (or Code Analysis for fellow TFS users) is more based on practices, so the decision becomes more technical than personal and stylistic.

joseph.ferris