Browse DevX
Sign up for e-mail newsletters from DevX


Maintain Better Coding Standards with Ease Using Checkstyle : Page 4

Coding standards are a time-honored and widely respected programming best practice. However, they are not always easy to put into action. Find out how Checkstyle can help you define and enforce a set of coding standards and promote good and consistent programming habits across your team.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

Integrating Checkstyle into the Build Process
Once you have defined and agreed upon a coding standard, it needs to be integrated into the daily routine. Integrating a Checkstyle plug-in into the IDE on each developer machine is a good start. However, coding standards really need to be enforced and verified systematically across the whole project. The nightly project build is often a good place to do this.

Checkstyle is delivered with an Ant task, which can be used to generate a report in HTML form. Maven integrates Checkstyle reports "out-of-the-box," via the Maven Checkstyle Plugin (see Figure 6). Whatever build tool you are using, Checkstyle audits should be run on the entire project at least once daily, and the results published on the project Web site.

Figure 6. Reporting: The screen shot shows a Checkstyle report generated by Maven.

It is a good idea to put your project Checkstyle configuration file under source control in the project, and refer to the same file from both the developer work environments and the build tool. This helps to ensure that the same standards will be applied on developer machines and in the build process.

Adopting Coding Standards
Like so many other things in software project management, a good dose of people skills will help you succeed in a new coding standards implementation.

The high priority of the project needs to be clear from the outset. Management (both the project manager and high-level management) must make sure developers understand that code standards are important or they'll never be enforced. It is one thing to automatically generate (and even publish) code audits, it is another to make them part of developer daily routine. Individual mentoring and coaching can be useful here. Another approach is to review code audit results in project meetings. Whatever techniques are used, the key is to get and maintain developer buy-in.

Coding Standards and Code Reviews
It is important to note that automatic source code audits do not by any means replace code reviews. When well used, code reviews can be a powerful tool for software quality improvement. Code reviews are an essentially human activity, as they rely heavily on human judgment to be efficient.

However, Checkstyle reports can make code reviews easier and faster by automating the numerous fastidious checks that make up a set of coding standards. This lets code reviewers concentrate on more high-level issues, and also saves time by ensuring that the code is clear and easily readable.

Coding standards will cost you some time at the outset, while developers get used to the new way of working. This is where developer and management buy-in is important. If developers feel that coding standards have strong support from project and company management, they should quickly become a normal part of developer work. Once developers have fully adopted the coding standards, the costs of applying them will be minimized and benefits will become apparent.

John Ferguson Smart is principal consultant at Wakaleo Consulting, a company that provides consulting, training, and mentoring services in Enterprise Java and Agile Development. Well known in the Java community for his many published articles and talks, he is also the author of the book Java Power Tools.
Thanks for your registration, follow us on our social networks to keep up-to-date