Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Blog: blogs.msdn.com/ zainnab
Code Metrics What 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 […]” “[…] a set of software measures […]”
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 Info Raw count of IL lines Not a good measure by itself Stats N/A when used alone Code Analysis N/A
Cyclomatic Complexity Basic Info Count of decisions More decisions means more errors Used often with LOC Stats 10 Suggested upper limit Code Analysis CA Upper limit
Depth of Inheritance (DIT) Basic Info The maximum length from the node to the root of the inheritance tree Three assumptions Deeper == harder to predict behavior Deeper == greater design complexity Deeper == more reuse of code Stats Low Less complex Less reuse of code High More complex More reuse of code 5 or 6 for upper limit Code Analysis CA OOD_ChidamberKemerer94.pdf
Class Coupling / Coupling Between Objects (CBO) Basic Info Number of classes a single class uses Stats 9 Upper limit Code Analysis CA for class 30 for method Kemerer94.pdf
Maintainability Index Basic Info Calculates an index value between 0 and 100 that represents the relative ease of maintaining the code Stats High == good Low == bad Ratings Green (20 – 100) Yellow (10 – 19) Red (0 – 9) Code Analysis CA or lower threshold
Using the Tool Window