Programming standards refer to the minimum expected quality of code for a given deliverable. These standards can be met by providing software engineers with a set of rules to apply throughout their development cycle.
Enforcing a programming standard doesn’t have to be a complex task. There are hundreds of widely adopted standards for the vast majority of programming languages. There is the Airbnb Javascript Style Guide, C++ Core Guidelines, and more than likely one for the programming language of your choice.
The rise of linters and code formatters such as ESlint and Prettier has made it easier to apply these programming standards to your project. When set up correctly linters will automatically flag and sometimes even fix antipatterns in your code.
Programming standards help ensure a congruent code base by creating a standard approach to solving problems. This reaps rewards in reduced technical debt and improved code maintainability.
Even with the use of software designed to help enforce programming standards, software engineers still break the rules. They fall into traps and ignore when a rule has been broken.
Example 1: Rule broken: All variable names should be written in camelCase.
var DVLAYearOfManufacture = 2018; // incorrect
The engineer assumes the word DVLA should be capitalized because it is generally represented in uppercase online. But this thinking goes against our rule. The rules in our programming standard will make the decision, not the engineer.
Don’t let your external knowledge take precedence over the rules in our programming standard.
var dvlaYearOfManufacture = 2018; // incorrect
Example 2: Rule broken: All variable names should be written in camelCase.
const MAX_ATTEMPTS = 5; // incorrect
Since the variable is a constant, the engineer assumes it should be capitalized, words separated by underscores from their learning at university. But again, this goes against our rule.
const maxAttempts = 5; // correct
Using a programming standard in your project is a great way to create a more congruent and maintainable code base.
Make use of linters and code formatters to easily enforce a standard across a project.
Avoid traps where your thoughts and feelings override a rule given in the standard.
