Coding Standards and Effective Implementation
Why Coding Standards
Due to the advancement of programming languages (from sequential to procedural and later to modular and OOP), multiple people are able to work simultaneously on the same project. The coding style of each programmer is different and there requires a need for coding standards. As the code written by one programmer is often used or extended by another programmer, the importance of coding standards becomes paramount.
The coding standard varies with languages based on the nature of the language. For example Hungarian notation, which was widely followed by C programmers as a standard, insisted for a data type notation as prefix when defining variable names. However in strongly typed languages like Java, it has less significance and so not a part of the default coding standard.
How Coding Standards are defined
Most of the cases the project team will adopt a standard that is recommended by the community associated with that language. For example in the case of Java, there is a de-facto standard defined by the creators itself (SUN Microsystems / Oracle)
Some companies will customize these standards based on the nature of the work they are involved in like new / maintenance project etc. For example some custom programming standards are against the use of ternary operators as it impacts the readability of the code.
Implementation of Coding Standards
Implementation of coding standards is the most difficult part. Once a coding standard is rolled out, the concerned authority needs to make sure that it is strictly followed by each of the project members. Regular audits are required to make sure that there are no violations.
Difficulty in following the coding Standards
Following are some of the reasons why developers fail to follow coding standards
- Lack of discipline to follow standards.
- Time to Adapt: The members of the team might be consultants coming from various companies or project teams where they are used to follow different variations of the standard. In such circumstances they need some time to adjust with the new standard.
How to enforce Coding Standards
There is no point in rolling out coding standards without proper measures for implementing it. The measures MUST cover the following
- The developers MUST be provided with a provision to verify the code against the coding standards with the help of IDE tools. The best one I know is “Checkstyle” for Java where all the coding standard violations will appear as “Warnings”.
- It MUST be a collective effort where majority of the auditing is done with in the project team as a part of their day today work instead of waiting to get audited by a third party. So when a team member notices an issue, they MUST correct it and check in the code irrespective of who has caused it. However they can notify the team about such a bad check-in.
- Blocking the check-in: This is the strictest way of implementing standards where a pre-hook is applied which will check for standard violations before allowing codes to check-in to repository.
How Rhoodi can help implementing Coding Standards for Ruby
There is a gem available in Ruby which can play the role of “Checkstyle” for Java. The details of it are available at http://rubydoc.info/gems/roodi/3.3.1/frames. There are provisions in the Gem to customize the coding standards, to add it to the build etc. Also we need to investigate whether Rhoodi can be integrated with IDEs like Eclipse / Netbeans so that standard violations will be available as warnings to the developers.