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):
- Uniformity of code, comments and application of design patterns
- New developers – familiar with your coding standard – require less overhead thus quicker ramp up on your code base.
- 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.
- 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.
- Easy to obtain “linting” tools for coding standards that have industry wide acceptance.
- 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:
- 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.
- Linux Kernel’s coding style – I’m surprised they use 8 character tabs. Thats really wide indentation.
- 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.
- GNU coding standards – Mainly stylistic but also mixed with real world guidance of best practices for defensive programming and consistency.