Coding standards

So, I wasn’t sure what the subject of my first real post should be. So I picked coding standards.

What are coding standards?
Simply put – coding standards are well… standards. They help shape robust software by creating a uniform conventions and patterns that everyone uses.

What are the benefits of having coding standards?
There are variety of benefits including (and not limited to):

  1. Uniformity of code, comments and application of design patterns
  2. New developers – familiar with your coding standard – require less overhead thus quicker ramp up on your code base.
  3. Reduces possibility of bugs in your code as developers can easily follow the code and have a ready reference for different situations they might encounter.
  4. Prevent esoteric language features from introducing bad code. For example – C++ is a beast of a language. Some developers might use features like templates and exceptions, although are not esoteric features, can introduce unintended performance penalties.
  5. Easy to obtain “linting” tools for coding standards that have industry wide acceptance.
  6. Documentation can be easily generated. For example if everyone on your project wrote their comments in Doxygen format, you can easily machine generate the documentation for your code.

There are various other advantages of having coding standards but it’s difficult to enumerate all of them. Here are a few coding standards that are widely adopted in the industry:

  1. Google Style Guide – Has variety of style guides available like C++, Python, Shell Script, Javascript etc. What I like about their guide is – they offer the reader PROs and CONs for their recommendation. Remember not all their recommendations apply in every situation.
  2. NASA’s JPL offers few guides. Of course they build rockets and interplanetary space vehicles so it’s not applicable to everyone but their recommendations are very interesting. Interestingly they also are working on a draft for Java.
  3. Linux Kernel’s coding style – I’m surprised they use 8 character tabs. Thats really wide indentation.
  4. Perl’s style guide - offers stylistic guidance for Perl programs. I recently came across various rants on the web and although I was initially opposed to Perl (it has it’s pitfalls), I was impressed by the amazing amount of documentation that the language provides as well as the amount of documentation in CPAN module. I would consider it high quality software. Besides Perl offers all kinds of tools from documentation / man-page generation (try perldoc on any module) to linting tools such as perlcritic.
  5. GNU coding standards – Mainly stylistic but also mixed with real world guidance of best practices for defensive programming and consistency.