Visual Studio Code Metrics

12
Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: [email protected] Twitter: @zainnab Blog: blogs.msdn.com/ zainnab

Transcript of Visual Studio Code Metrics

Page 1: Visual Studio Code Metrics

Visual StudioTips and Tricks

Code Metrics

Zain Naboulsi

Sr. Developer Evangelist

Microsoft

Email:[email protected]:@zainnab

Blog:blogs.msdn.com/

zainnab

Page 2: Visual Studio Code Metrics
Page 3: Visual Studio Code Metrics

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

Page 4: Visual Studio Code Metrics

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

Page 5: Visual Studio Code Metrics

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

Page 6: Visual Studio Code Metrics

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

Page 7: Visual Studio Code Metrics

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

Page 8: Visual Studio Code Metrics

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

Page 9: Visual Studio Code Metrics

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

Page 10: Visual Studio Code Metrics

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

Page 11: Visual Studio Code Metrics

Using the Tool Window

Page 12: Visual Studio Code Metrics