KhronosGroup / KSCAF_DocRequirements

Khronos Safety Critical Advisory Forum’s minimum requirements for developing a safety critical technology specification.
3 stars 1 forks source link

Code complexity should be low #23

Open irudkin opened 6 years ago

irudkin commented 6 years ago

Text entered:

Many of the safety standards require that the code is written in the least complex manor. Many software code quality assessment tools score code on its cyclomatic complexity. The less complex means there are likely less linearly independent paths through a program's source code which results in a lower score. A lower score is a better score and is an indication that the code is easier to understand and so modify with less chance of unforeseen behavior.

The API and its functions' signatures play an important part on how the implementation is coded. The number of parameters in a function should kept to a minimum to help reduce complexity.

If numerous parameters are required consider if they are necessary for immediately use or just passing through to other private functions. If that is the case it is good practice to encapsulate those parameters in to an object such as a 'C' structure. Use of a structure not only reduces the size of the function signature it helps reduce the complexity of the code supporting that function and so helps with code maintenance. Should it be required a function's parameter is no longer required or a new one is needed function signatures down the line also do not have to change to handle the change.

irudkin commented 6 years ago

This text needs review