|
Resources
|
What is a programming rule?A programming rule is the description of a set of constraints to respect when writing software code. There are several types of programming rules:
- naming rules: they define the way identifiers are used in an application to make the code easier to read and help to detect errors.
Example: all constant names must be in UPPERCASE. - portability rules: they identify language constructs in the code that can induce a different behavior depending on the operating system or the microprocessor being used.
Example: two floating numbers shouldn't be compared using strict equality. - rules that protect from language difficulties.
Example for the C language: do not mix up the "=" used for affecting a value and the "==" used to compare. - presentation rules that make the code easier to read.
Example: write a single instruction per line. - rules that make application maintenance easier.
Example: when writing code in C, C++ or Java, use opening and closing braces in the if and then blocs of a test. - rules that limit code complexity.
Example: limit the complexity of expressions to 4 operators at the most. - rules that allow better code structure.
Example: declare shared variables in a header file.
Checking programming rules
Checking a set of programming rules is usually done during a source code audit. It can either be done manually by reading the source code, or automatized using a tool that points out rule violations. Logiscope allows to check programming rules for C, C++, ADA and Java languages.
Standard programming rules
- MISRA C: a set of rules initially conceived for the automobile industry and now widely used.
- MISRA C++: a version of the MISRA C rules adapted to the C++ language
- Scott Meyers rules: these rules are described in the following books:
- "Effective C++: 50 Specific Ways to Improve Your Programs and Designs" (Addison-Wesley, second dition, 1997, ISBN: 0-201-92488-9)
- "More Effective C++: 35 New Ways To Improve Your Programs And Designs" (Addison-Wesley, first edition, 1996, ISBN: 0-201-63371-X).
|