How do you measure that your code
is maintainable?
There is no such standard measure
exists in IT industry that indicates that your code is maintainable. However
there can be several disciplines which you can use to interpret maintainability
of your code. One way of arriving to this is to identify different high
priority code metrics and summarization of weightage of each of those metrics. For
example look at the below calculation,
Code
Metrics
|
Weightge
in %
|
Code coverage
|
50
|
Cyclomatic Complexity
|
20
|
Duplicates
|
10
|
Coupling
|
10
|
Large Class
|
5
|
Large Methods
|
5
|
Total
|
100
|
The above table illustrates the
weightage derived from each metrics considered to calculate the maintainability
index of software. The weightage can be calculated based on the target metrics you
have defined for each item on the list. This calculation is quite interesting
and can be applied to any code that needs serious attentions. It is mostly
applied for legacy code that is hard to understand or refractor. Any such
statistical representation will help to check the progress of legacy code
module.
Based on the total weightage
calculated, you may want to represent your software as below,
Maintainability index
|
Summery
|
0-30
|
Need serious attention (Bad)
|
30-50
|
Need improvements (Average)
|
50-70
|
Maintainable, can be improved (Good)
|
70-100
|
A very good maintainable code (Excellent)
|
Before jumping into this
calculation it is important to decide on the target metrics that the software should
be adhered to. That will basically set the goal and the trend you need to define
in iterations. The target metrics can be derived from the base metrics of your
current code base. Identify the amount of improvement you can do based on the base
metrics and that can be converted into small iterations. Or you can add those as
a technical story into your backlog. Identify or add some slack time into your
iteration planning or into your estimation to address those. Following the every
iteration you can have check on your maintainability index.
The above calculation I have shown is not a standard one, I have just quoted an example. The calculations and assumptions can be different to different team based on their internal understanding or discussions. However I assume that these types of measurements should be done with proper discussion with the team and also the stack holders.
Be careful while selecting the
kind of metrics you are going to use for the calculation of maintainability index.
Do not take too many metrics to be worked on, discuss within your team and
identify 4 or 5 very important metrics that make sense to make you code maintainable
and readable. Developers or Architects sometime tends to collect too many
metrics but it never make any sense as most of the metrics does not have any
direct impact on the maintainability of the code. For example, metrics like
unused types, code comments does not have any direct impact on your code maintainability
than cyclomatic complexity or class coupling. Understand the rationale behind
all of them and choose the one that really helps. Others can be addressed later
or will be addressed indirectly during refactoring.
Comments
Post a Comment