visual studio code metrics
TRANSCRIPT
Visual StudioTips and Tricks
Code Metrics
Zain Naboulsi
Sr. Developer Evangelist
Microsoft
Email:[email protected]:@zainnab
Blog:blogs.msdn.com/
zainnab
Code MetricsWhat are they?
Why should I care?
Lines of Code (LOC)
Cyclomatic Complexity
Class Coupling / Coupling Between Objects (CBO)
Depth of Inheritance Tree (DIT)
Maintainability Index
Using the Tool Window
What are they?
“[…]a measure of some property of a piece of software or its specifications […]”http://en.wikipedia.org/wiki/Software_metric
“[…] a set of software measures […]”http://msdn.microsoft.com/en-us/library/bb385914.aspx
Why should I care?
Find those areas that are (statistically) more likely to produce problems
Determine where to focus limited resources
Understand the current state of a solution / project
Keep track of where we have been and where we are going
Lines of Code (LOC)
Basic InfoRaw count of IL linesNot a good measure by itself
StatsN/A when used alone
Code AnalysisN/A
http://academic.research.microsoft.com/Paper/2101790.aspx
Cyclomatic ComplexityBasic Info
Count of decisionsMore decisions means more errorsUsed often with LOC
Stats10 Suggested upper limit
Code AnalysisCA1502Avoid excessive complexity25
http://www.mccabe.com/pdf/mccabe-nist235r.pdf
Depth of Inheritance (DIT)Basic Info
The maximum length from the node to the root of the inheritance treeThree assumptions
Deeper == harder to predict behaviorDeeper == greater design complexityDeeper == more reuse of code
StatsLow
Less complexLess reuse of code
HighMore complexMore reuse of code
5 or 6 for upper limit
Code AnalysisCA1501Avoid excessive inheritance4 http://www.pitt.edu/~ckemerer/CK%20research%20papers/MetricFor
OOD_ChidamberKemerer94.pdf
Class Coupling / Coupling Between Objects (CBO)
Basic InfoNumber of classes a single class uses
Stats9Upper limit
Code AnalysisCA1506Avoid excessive class coupling80 for class30 for method http://www.pitt.edu/~ckemerer/CK%20research%20papers/MetricForOOD_Chidamber
Kemerer94.pdf
Maintainability IndexBasic Info
Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code
StatsHigh == goodLow == badRatings
Green (20 – 100)Yellow (10 – 19)Red (0 – 9)
Code AnalysisCA1505Avoid unmaintainable code19 or lower
Using the Tool Window