posted on Saturday, December 04, 2004 9:36 PM by davidboschmans

Enforcing naming conventions

Brad Adams asks if anyone has tried out the .NET Design Guidelines naming conventions tool which is part of DevPartner CodeReview.
Well, actually I do use it. As a [Compuware] .NET consultant I'm using 
DevPartner Studio Professional Edition on a daily basis. The code review tool helps me in assuring the use of our defined coding practices and standards by all developers in the team. This improves the reliability and maintainability of the application, it trains the developers in the use of "best practices" and it gives me the ability to share the results of debugging or code review with others on the team after a successful build on the build server.

CodeReview also helps me find problems in following categories:

  • Component Object Model
  • Database
  • Internationalization
  • Microsoft Transaction Manager
  • Microsoft Message Queue
  • Web classes
  • Logic—known bugs and common, but fatal, mistakes
  • Performance—conditions that reduce execution speed and bloat .exe size
  • Portability—conditions which limit a project to specific operating systems versions
  • Usability—interface issues like duplicate or missing accelerator keys and help
  • Windows API—side effects, tips and other issues
  • Language—non-compliant object naming, variable naming and coding styles.
  • .NET migration—identifies and describes code that must be modified to port to Visual Basic .NET.

As an answer to Brad's question let's focus on the naming analysis. CodeReview lets you choose between "Hungarian" and "Naming Guidelines" for the naming analysis to use. As I assume Brad is interested in the "naming guidelines" a small wrap-up:  

The Naming Guidelines naming analyzer is patterned after the Visual Studio .NET Framework naming guidelines. Microsoft adopted the Visual Studio .NET naming guidelines to support the .NET Framework. The Visual Studio .NET naming guidelines ensure that consistent, predictable, and manageable naming practices are applied to .NET Framework types in a managed class library.
The Naming Guidelines naming analyzer examines parameters, classes, namespaces, methods, delegates, enums, structs, interfaces, and variables. It looks for naming violations in the source code related to capitalization, case sensitivity, abbreviations and acronyms, and syntax for namespaces and other .NET Framework identifiers.

The CodeReview Rule Manager contained in DevPartner is an extensible rules database that is based on the Microsoft Visual Studio programming standards. The rules database is maintained and stored in the Rule Manager. The Rule Manager is a standalone application that accompanies the DevPartner code review feature.
The "Naming Guidelines" rule set contains a small set of rules for checking the .NET Framework Naming Guidelines as they are defined
here. This works fine however some more detailed and specified rules provided out of the box could improve the productivity of checking compliancy with the naming guidelines.

Some of the naming guidelines rules:

  • Class name has the same name as an enclosing namespace
  • Method names should not be unique only in case
  • Namespace names should not be unique only in case
  • Type names should not be unique only in case
  • Parameter names should not be unique only in case
  • Parameter names should not be the same as the method name
  • A method name implies the same functionality as a property

These rules are checked "by default", but of course you can extend the rules database with your own coding rules to fit the user’s organizational requirements.

Would I recommend it? Well ... yes and no. Purchasing DevPartner Studio Professional Edition only for doing naming analysis would be a waste of money in my opinion. There are probably other tools (FxCop, etc.) with the same or greater functionality available. However when using DevPartner CodeReview not only for naming analysis but also for checking date formatting rules, design time properties, internationalization rules, logic rules, web applications and performance rules, I highly recommend it. Why? As a senior developer and code reviewer it frees up a lot of my time, decreases the amount of defects and increases reliability of the applications.
Note that besides Source Code CodeReview also Error detection and diagnosis, Memory analysis, Code coverage analysis, Performance analysis and Distributed application analysis are included in
DevPartner Studio Professional Edition. Add to this the upcoming tools Fault Simulator and SecurityChecker, and DPS is still a high value proposition. 

Comments