MI AND CMI
上一篇 /
下一篇 2014-12-22 14:21:13
MI standard for Maintainability Index, which is a number reported by Glority MI tools.
Generally saying, we treat code is easier to maintain if:
- Each method has fewer lines of code.
- Each method has simpiler logic.
- Each method has good document and inline comments.
MI With Comment = 171 - 5.2ln(aveV) - 0.23aveV(g') - 16.2ln(aveLOC) + (50 * sin(sqrt(2.46*aveCM))
MI Withut Comment = 171 - 5.2ln(aveV) - 0.23aveV(g') - 16.2ln(aveLOC)
ave
You can see all above factors are ave(average based). ave here means average per methods. Generally saying, smaller method/functions will have better MI.
aveV
aveV isHalstead volumes. this is a metric to measure how many info the code contains. It's a number base the number of operators and operands in the code.
The lower aveV, the easier to maintain the code since it contains less info.
aveV(g')
aveV(g') is averageCyclomatic Complexity. This is a metric to measure how complex the code is logically. it will count brances in the code(if/else, while, for, swith/case).
The lower aveV(g'), the easier to maintain the code
aveLOC
aveLOC is Lines Of Code. Less lines is better
aveCM
aveCM = Lines Of Comments / (Lines of Comments + Lines of Source Code), so this is a number in0, 1.
More comments is easier to maintian, but the impoertance of the comments comes lower when the comments rate more than 0.3.
收藏
举报
TAG: