All too frequently a programmer is left to produce code, without standards or quality assurance. It is only after a major problem that the months and in some cases, the years of programming are found to be worthless. Some control on the code being produced is essential – and this starts with a well documented Coding Standard.
No matter how busy you are, a Coding Standard will be a time saver in the long run – it is fundamental to good programming. Coding Standards and programming productivity go hand-in-hand. Adhering to a Coding Standard will lead to a significant increase in development productivity, whatever the programming language. A consistently applied set of Coding conventions will standardise the structure and coding style of an application, so a programmer can readily read and understand other programmers’ code, as well as their own code.
Good Coding Standards result in precise, readable, and unambiguous source code that is consistent and as intuitive as is possible. The object of a Coding Standard is to make the program easy to read and understand without cramping the programmer’s natural creativity with excessive constraints and arbitrary restrictions.
Maintenance Costs
Following a Coding Standard will increase productivity, not only to system development, but increase productivity in enhancing and maintaining systems as well. And it is also important to control maintenance costs- these can constitute most of the lifetime cost of software.
To reduce the high maintenance cost, it is essential to have code written that can be easily deciphered and enhanced by any other programmer in your Company. This is important, as usually very little software is maintained by the original programmer.
Enforcing the Standard
All the programmers should agree on the Coding Standard. Once agreement has been reached, the Standard must be enforced, as part of quality assurance. The use of the agreed coding techniques and good programming practices play an important role in software quality and performance. By consistently applying a well-defined Coding Standard, a team of programmers working on a software project is more likely to yield quality software system code that is intelligible, error free, cost effective and maintainable.
Here then are some ideas to help create your Coding Standard. Make it short and to the point:
Readable Code
The code must be created so that it is easy for other programmers to understand. It should not be written only with just the computer in mind. The code should be easily readable, with lots of white space.
Blocks of Code
Blocks of Code should be broken into sections that are well defined and understandable procedure chunks. It may be helpful to use a “Main Line” to split a lengthy procedure.
Code Indentation
Those “If” “If” “Else” “Else” constructs are hard to follow, if the indentation of control structures is inconsistent.
Variable Names
The variable naming convention should be well thought out, meaningful and consistently applied. The variable name should describe the content of the variable. Try not to have abbreviations, unless they are consistently applied. The standards for capitals, Camel or Pascal case need to be set.
Procedure Names
Much as for variable naming conventions, procedure names should describe their purpose.
Code Documentation
No matter how well the code is written, changes or enhancements will eventually be required. Time should be spent when actually writing the code, commenting on the intent and technical aspects of the code. This will save time and effort later on.
In addition to external documentation, all code should be liberally documented with comments. Each procedure should have a heading with comments describing the input, output and function of the procedure.
Complex Constructs
There is always the temptation to use the latest and greatest feature – this is true especially with inexperienced programmers. Complexity and the esoteric will make a program code difficult to follow, maintain and debug. Simplicity, above all, must be enforced.
Keep the Coding Simple
If another programmer cannot understand, at a glance, what the Code is all about, then the Code is badly written. So often it becomes necessary when debugging or enhancing code, that the code be rewritten. This is a costly exercise for the company as well as being a non-productive and wasted effort.
Isolate Complex Code
There will be the occasion when simplicity must give way to complexity, when functionality or performance is required. In these cases (hopefully, few and far between), the complex code should be isolated in a “black box” library procedure.
Reusable Code
The Coding Standard should include the gathering and documentation of reusable Code. With reusable Code, that is Code that is not duplicated throughout an entire organisation, the programmers will build programs faster – and programs that run faster. Using less Code means greater productivity and faster development cycles. By using the same Code repeatedly by every programmer in every project, errors are identified and eliminated sooner.