Code Quality Standards

With the boom of the internet in the late ’90s and the early 2000s, the IT industry saw a huge revolution. With companies like Facebook, Google, and Amazon launching some exciting products and quickly gaining the customer base, we were quite sure that the next few years will be dominated by the IT Industry and more of the exciting products and stuff was yet to come. We were then introduced to some trending technologies like Artificial Intelligence, Data Science, Machine Learning, Deep Learning, Virtual Reality, and Augmented Reality.

While all of these technologies sound very cool and are interesting to work with as well, the base of all these trending technologies is a Programming Language.

Programmers or Developers are required to stick to certain standards when they are writing production-ready codes. These standards vary from company to company. This is the reason why companies spend a lot of money and resources while training fresh graduates. Therefore having knowledge of code quality standards is very important for any developer. In this article, we will be discussing ‘code quality standards’ and will also have a look at why it is essential to follow them.

Software is required to be safe, secure, portable, testable, maintainable, and reliable. Coding rules, standards, and guidelines help to ensure whether or not the end product satisfies all of the above requirements. Coding Standards also vary from one Programming Language to another. C Programming Language has a different coding standard whereas C++ has another set of rules to ensure the code quality. We will also discuss this at a later stage. As of now, we have listed below some coding standards that are common across all programming languages.

  • Naming Conventions for Local variables, Global variables, and Functions: It goes without saying that variables and functions should be named in such a way that it should convey the reason behind using the particular name. Also, local variables and functions should be written using Camel Case i.e. starting with small letters whereas Global variables names should start with Capital Letters.
  • Indentation: Code readability is quite an essential factor when writing production-ready codes. The nested blocks must be appropriately spaced and indented. The opening and closing of braces must be from a new line and it is also important to leave a space after comma while writing the arguments of a function.
  • Standard Headers for Different Modules: We have always mentioned the fact that a good code is a code that is well maintained. In order to achieve better maintainability of the code, it is important that the header of different modules should follow some standard format and information. It should contain the name of the module, author of the module, the date of creation, modification history, and a guide regarding different functions used in the module and the input and the output parameters.
  • DRY Principle: DRY stands for Don’t Repeat Yourself. Many times it happens that we are calculating/using the same thing again and again which increases the number of lines in the code. The longer the code gets, the more difficult it becomes to maintain it. Therefore this principle comes in very handy. It asks the developers to check if they can convert certain parts of code into functions and simply call them as and when required. Therefore, the code becomes more readable and maintainable.
  • Well Documented: A well-documented code is liked by one and all. Documentation helps the developers know the intention behind writing this piece of code and it gives them an insight about what to expect in further iterations. At the same time, it is very important to write comments in your code. It increases the understandability of the code and it becomes easier not only for you but your fellow developers as well, in case someone wants to make certain modifications in the code.

On researching more on this, we landed on the Microsoft Documentation Page that talks about Coding Style Conventions. They follow ‘Hungarian’ notation and they include variable prefix notation that gives variable names a suggestion of the type of the variable. For example, they use the prefix ‘a’ for an array, ‘b’ for boolean, ‘f’ for a flag, ‘i’ for integer, etc. The format they follow while writing comments is attached below.

/*--------------------------------------------------------------------
Plain block of comment text that usually takes several lines.
Plain block of comment text that usually takes several lines.
--------------------------------------------------------------------*/

The Class Declaration Header is also attached below for your reference

/*C+C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C+++C
Class:    CMyClass

Summary:  Short summary of the purpose and content of CMyClass.

Short summary of the purpose and content of CMyClass.

Methods:  MyMethodOne
              Short description of MyMethodOne.
            MyMethodTwo
              Short description of MyMethodTwo.
            CMyClass
              Constructor.
            ~CMyClass
              Destructor.
C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C---C-C*/

These are only some examples and you can follow the link mentioned above to get a complete idea of their coding style and practices.

Talking about different coding standards for different programming languages, Embedded C has different coding standards like MISRA and CERT while Embedded C++ has standards like High-Intensity C++, JSF C++, and Autosar.

Without going into much detail, there are different external coding standards as well which include IEC 61508, ISO 26262, IEC 62061, etc.


However, Code Review is another part that plays a great role in the success of software. A proper Code Review is very essential before pushing a code into production.  

We hope this article gave you valuable insights regarding the Code quality standards and we also hope you will sincerely follow the next time while coding anything.

Want to learn more about code quality? Take a look at the "Complete Code Quality Guide".

FURTHER READING

- Complete Code Quality Guide

- Code Quality Tools

- Code Quality Metrics

- How to measure, check and improve code quality:

-- How To Check Code Quality?

-- How To Measure Code Quality

-- How Can I Improve My Code Quality

-- How To Build A Website With Good Quality Code?

Updated on the 1st of November, 2021