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

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

Embed Size (px)

Citation preview

Page 1: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com
Page 3: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

Cyclomatic ComplexityBasic Info

Count of decisionsMore decisions means more errorsUsed often with LOC

Stats10 Suggested upper limit

Code AnalysisCA150225 Upper limit

http://www.mccabe.com/pdf/mccabe-nist235r.pdf

Page 8: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 AnalysisCA1501 http://www.pitt.edu/~ckemerer/CK%20research%20papers/MetricFor

OOD_ChidamberKemerer94.pdf

Page 9: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

Class Coupling / Coupling Between Objects (CBO)

Basic InfoNumber of classes a single class uses

Stats9Upper limit

Code AnalysisCA150680 for class30 for method

http://www.pitt.edu/~ckemerer/CK%20research%20papers/MetricForOOD_ChidamberKemerer94.pdf

Page 10: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

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 AnalysisCA150519 or lower threshold

Page 11: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com

Using the Tool Window

Page 12: Visual Studio Tips and Tricks Code Metrics Zain Naboulsi Sr. Developer Evangelist Microsoft Email: zainnab@microsoft.com Twitter: @zainnab Blog: blogs.msdn.com