views:

144

answers:

3

Did a quick search but could not find anything about this.

I guess all of you know that the Visual Studio Code Analysis is quite nitpicking and gives warnings about a lot of things. Does anybody know how well Microsoft follow this themselves..? That is, if I were to run a code analysis on their assemblies, would the warnings be none or very few (perhaps surpress warning with a justification..?).

A: 

While I don't work for Microsoft. People on here and the rest of the Internet state that even Microsoft themselves do not always follow the standards that their tools check for. After all, standards and best practices do not make sense for every solution.

There are some examples of this with code from .NET, try searching for such examples.

Finglas
+5  A: 

Most of the things that code analysis (or FXCop) check are closely based on the ".NET Framework Library Design Guidelines" (either the book, or on MSDN).

However those guidelines (especially in the book) have caveats, not all apply in all circumstances.

There are plenty of indications that MS do use these tools, but I assume they do have reasons to not apply all the rules all the time, as any other project does.

Richard
Forgot about that book. Interesting read.
Finglas
FXCop isn't the only Code Analysis tool from or at Microsoft. Ever heard of PreFix and PreFast?
bitcrazed
@bitcrazed: IIRC they are for native code. This question is tagged [.net]. The VS code analysis is specifically FXCop integrated into VS.
Richard
Note that historically most of Microsoft's products were built in native code and thus would not be analyzed using FXCop. This is starting to change as teams are increasingly writing managed code so FXCop usage is accelerating rapidly. Most teams also mandate that all managed code must be "FXCop clean" by the end of each milestone.As mentioned above, not all rules apply in all scenarios. As I (and others) state elsewhere, there are caveats and specific scenarios where particular rules may be bent. Just be sure you REALLY DO need to exclude a rule before doing so.
bitcrazed
+2  A: 

There are two core tools used widely at Microsoft for Code Analysis: FXCop for managed code and PreFast for native C++.

Historically, while not every team has thoroughly enforced the use of CA when building their products, there's been a significant upswing over the last 3-4 years in particular in the number of teams that now enforce pretty stringent CA requirements on their feature teams and on the product as a whole.

For example, in Vista, the Windows team essentially took 3 months off product development and SAL-annotated the vast majority of their key method and function declarations. in Win7, they mandated that all new code had to comply with a set of requirements for SAL-annotating key scenarios (primarily to reduce the likelihood of buffer overruns). In Win8 they're going further still and are incorporating new SAL annotations for a number of key scenarios. Combined with improved compilers and tools like PreFast (now build into VS 2010 Pro and up), they and you can find and eliminate potential issues before the product is released.

Note that the warnings issues by CA (whichever CA tool you choose to use) will always require overrides - sometimes, there's a really good reason as to why the code has to do what it does. But you should only override if you're ABSOLUTELY sure it's necessary and appropriate. NEVER turn off a warning because you don't understand it and never turn off a warning if you can't be bothered to fix it.

bitcrazed