The Religion of Coding Style

I’ve been doing some investigation of different “Coding Style Enforcement” tools (primarily for C# code) recently on behalf of a Bing v-team on coding conventions and I’ve learned a few things:

1. ReSharper kicks ass.

2. Developers are willing to shed blood over coding style preferences.

3. ReSharper really kicks ass.

First a quick introduction on a few tools in the space:

ReSharper (or R#) is a Visual Studio add-on that does on the fly code analysis, and is also great for refactoring code. It gives you nice little squiggly lines that represent errors, warnings, suggestions, or hints for your code as you type. The thing that makes R# ‘leet is that it can also often fix issues for you.

StyleCop is a tool that was developed by Microsoft and is available under the MPL. It has a good stock set of rules that many Microsoft teams tend to follow (for the most part). Current versions now ship with a ReSharper add-on that really rocks, because R# can now automatically fix a lot of StyleCop issues and give R# style real time warnings as you type. The only downside is that as of right now StyleCop 4.6 hasn’t yet released (should come very soon), so there is no intergration with R# 6.0.

FxCop is a different breed of tool so I won’t go into great detail, but people often wonder what the difference is so I’ll touch on it briefly. FxCop analyzes built assemblies (not code) for design, localization, performance, or security issues. VS has built in FxCop integration that’s controllable via the Code Analysis tab at the project level.

CodeRush is a competitor to R#. Agent Smith is a competitor to StyleCop, only from what I can tell it is only available as a R# plugin. I don’t know much about either except that I’ve met people who use and think they’re cool.

That’s certainly not any kind of exhaustive list, but those are a few technologies that I’ve either played with or seen mentioned in the managed code style enforcement space. Some props go out to Scott Marlowe, I found his blog post to be a pretty good starting point for investigation.

Tools aside, the question that I hear posed on a fairly regular basis is “How much does adherence to coding conventions really matter?” My answer to this question has changed a bit throughout my development career. For the last few years I haven’t been huge on conventions, I’ve generally encouraged developers who work for me that the guiding principle should be to match the style of the project that you’re working in. I still believe this is probably the most important idea when contributing to a project, but I also find myself more compelled to accept coding standards for projects where more than a few developers are partying. There’s something beautiful about looking at code and not being able to tell who wrote it because the style is consistent across the board. It makes it easy to jump in on new projects because they’re always readable to me, not just the dude who wrote the code. It also avoids the kind of “should I use var or not” battles that tend to become religious crusades and can actually even fracture a team in extreme cases.

Speaking of var, I’ve become a huge believer lately in part because I started using QuickGraph which can result in some crazy nested generic types, but also because the default R# rules encourage it. I actually find myself agreeing with Michael Brennan’s arguments in favor of always using var. But then again, I’m not quite ready to shed anyone’s blood over it.