I use the term Coding Standards to refer to guidelines pertaining to the appearance of the source code, and the term Development Standards to refer to more general programming guidelines that an organization agrees to adhere to. In this sense, coding standards are “easy” given that there are numerous code-checking and formatting tools that can be applied to make adherence to coding standards a mechanical practice. Development Standards on the other hand, require some conscious discipline on the part of the developer and, although their validation can be partially automated, probably need some additional enforcement mechanisms such as pair programming, peer review, and code review. Often, Development Standards consist of avoiding practices that have been proven over time to result in poor quality code.
Let us examine the pros and cons of having standards in an organization. The primary reason for not having coding standards is that is nearly impossible for everyone to agree on them. Over time developers have evolved their own personal programming style and their are loath to modify it. Consequently, an enforced development standard will displease some people to some extent.
Now let us explore some of the main benefits that can reaped from adhering to a standard that will make it adopting it worthwhile.
Code Quality is the most obvious benefit of development standards. To give a simple example, consider several nested loops or conditionals. If there are no enclosing brackets it’s hard to tell where each one starts and ends leading to the possibility of a bug. Even if the developer who wrote it is adept at this sort of thing, it will not be as obvious to another developer who tries to understand or modify the code.
Code Readability is another benefit of Coding Standards. Large classes and methods with deeply nested loops are notoriously hard to understand and even harder to test. It is also much harder to understand a piece of code, as you leap from class to class, if each file has its own programming style.
Last but not least comes the necessity of maintaining the code over time. Software applications have surprisingly long lifetimes, usually surpassing the employment span of developers who work on it. Code that is hard to read and understand is harder to maintain and more bug-prone.
Tools for Monitoring Standards
There are several tools that can help developers adhere to coding standards, measure deviations from the standards, and report on code quality in general.
To begin with, standard IDEs such as Eclipse and NetBeans have formatting and style-checking tools and they come packaged with the Java conventions. Checkstyle is a tool that lets an architect or manager define any coding standards and reports violations. It comes with ant tasks and plugins for Eclipse and NetBeans. PMD is an excellent code quality tool that detects possible bugs, dead code, sub-optimal code, code duplication, and more. It is also highly configurable like checkstyle. Findbugs is a tool similar to PMD. Cobertura and Emma are tools that measure unit test coverage. Finally,
Hudson is an excellent continuous integration tool for Java with plugins for incorporating reports produced by all of the
tools mentioned here.