Monday, May 2, 2011

Why we need Coding Standards?

What Is the Coding Standard?

In a nutshell, it is a set of rules or guidelines used when writing the source code for a computer/software program. It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and help to maintain it.

Why we need it?

The best applications are coded properly. This sounds like an obvious statement, but by ‘properly’, I mean that the code not only does its job well but also is easy to maintain and debug. There is a lot of talk recently about the ‘maintainable code’ as it makes more sense that while facing any issue you are not spending time in understanding the code as its written in a way that is not easy to digest & understand. It also a great impact on the revenue of the company because if company is spending more time in maintaining the code than they have less resources/time to think about novel ideas & implement them as market niche & need is keep changing rapidly now a days.

With time & experience one’s adopt his own style of coding where he/she feels more comfortable but when the developers put together in a bigger project and if everyone tries to code in their own style than the confusion, conflict and complexity arises. By adopting the coding standards into your project, one can make sure that code is readable, intuitive and without any surprises because everybody who looks into your code they have the mindset of what to expect in the code as they have the company coding standard document. It also helps you as a develop to come back to your code after couple of weeks/months and still remember what each part is doing and what was the rational behind putting the logic in that particular way.

Some of the main points to consider while building the coding standards are: -

1. How you name the classes/object?

2. How you name the variables?

3. How you name the Constants?

4. How big are the functions/modules? Are they properly named with the functionality they perform? Are they properly called from different sources?

5. Is your code overall flexible? How easy is to do the change? Does it require a hell amount of time to do a minimum change (it happens if you hardcode values rather than using constants)

6. Does your code make use of block when necessary to make it more readable (for example when putting an if block which has lots of statements that can be easy understand if braces are properly used)?

7. Is your code properly indented?

8. Does your code have proper comments? Specially for the logic that is more completed and as a developer you think will aid the reader to understand specific complex parts of the code.

9. Do you create a common functionality in a separate entity (class/object etc.), which is easily reusable from different sources as per the need?

10. Is your code maintainable? If you or anyone else comes back to add new functionality or fix any existing issues, how much time they need to understand it and how easily they can make the change.

You need to discuss these as a team so that everybody is aware of what is expected from them while building any functionality.

The adoption of coding standards should not increase costs. Standards should take care of easy decisions for you, leaving you free to concentrate on the real work. Another reason for adopting coding standards is to pre-empt bugs as the cost of fixing a bug rises exponentially over time. Finding and fixing bugs in the development phase and preferably even prior to unit testing can save hours of time and resources later. Another common area for the adoption of a set of standards is on code commenting. Keep in mind that bad or out-of-date comments are worse than useless: they can cause others a great deal of wasted time and frustration. To quote Sun Microsystems: "When you feel compelled to add a comment, consider rewriting the code to make it clearer".

Now there are lot of tools available that can analyze your code for a particular coding standards (Sun/IBM etc) along with other key things hence adoption of coding standard is more common & easily manageable now as companies now expect a manageable code which adheres the company standards.

I have seen & analyzed it personally with my over ten years of software industry experience. I have gone through many different coding styles within different projects where different developers were involved. What I have learned is that it does not matter what coding standards/guidelines your company adopt, is it as suggested one by the software guru’s or a novel idea (only follows by that company), as long as its properly called out, documented and followed, it is easier for the future developers to adopt with it, read it properly, understand it and mainly maintain it within less time & with no or less effort.

No comments:

Post a Comment