Code Reviews Using Visual Studio Team System - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Code Reviews Using Visual Studio Team System

Description:

'Code review is the systematic examination of computer source code intended to ... the reader editing your own work is fraught with risk: you see what you thought ... – PowerPoint PPT presentation

Number of Views:188
Avg rating:3.0/5.0
Slides: 16
Provided by: stevea150
Category:

less

Transcript and Presenter's Notes

Title: Code Reviews Using Visual Studio Team System


1
Code ReviewsUsing Visual Studio Team System
2
Concepts and Principles
  • Code review is the systematic examination of
    computer source code intended to find and fix
    mistakes overlooked in the initial development
    phase, improving both the overall quality of
    software and the developers' skills.
  • Wikipedia

3
Why Perform Code Reviews
  • The least expensive way to eliminate bugs is to
    not introduce them. This comes from the quality
    revolution that transformed manufacturing during
    the 1970s. The principle is that the least
    expensive way to produce a product is to design
    quality into the process.
  • Waste indicates there is something wrong with the
    process. This comes from the lean manufacturing
    concepts in the iconic 1989 book Lean Thinking by
    James Womack and Daniel Jones
  • Bugs are like disease though surely part
    of the human condition they are an abomination we
    must seek to prevent. But how can one preempt
    them? Is there an inoculation for defects?
  • A Guide to Code Inspections, Jack G. Ganssle

4
Types of Code Review
  • Formal Code Review - A careful and detailed
    process with multiple participants and multiple
    phases.
  • The traditional way of performing code reviews
  • Software developers attend a series of meetings
    and review code line by line.
  • Makes use of formal inspections that are very
    thorough.
  • Advantages - Proven effective at finding defects
    in the code
  • Disadvantage Requires a high level of effort,
    often to much to be practical
  • Lightweight Code Review
  • Code Walkthrough
  • Pair programming
  • Tool-assisted code review

5
Visual Studio Team Suite Tools
  • Unit testing / Code Coverage
  • Within VSTS Code coverage is part of Unit Testing
  • Used as a validation that unit tests are covering
    the code paths and to identify code that was not
    tested.
  • Code Metrics - VSTS 2008 and 2010 generate the
    following metrics
  • Maintainability Index
  • Cyclomatic Complexity
  • Depth of Inheritance
  • Class Coupling
  • Lines of Code
  • Code Analysis
  • A set of best practice rules build into VSTS
    that the source code is evaluated against.

6
Visual Studio Code Metrics
  • Class Coupling
  • Indicates the total number of dependencies that
    the type has on other types.
  • Excludes primitive and built-in types such as
    Int32, String and Object
  • Includes Interface dependencies.
  • The higher the class coupling, the more likely
    changes in other types will ripple though the
    type.
  • Depth of Inheritance
  • Indicates the number of types that are above the
    type in the inheritance tree.
  • Does not include the depth of any implemented
    interfaces.
  • Deep inheritance trees can indicate
    over-engineering of a problem and can increase
    the complexity of testing and maintaining the
    application.

7
Code Metrics (Continued)
  • Cyclomatic Complexity
  • The total number of individual paths through the
    code.
  • This statistic is calculated by counting the
    number of decision points (such as if blocks,
    select case statements, and loops) and adding 1.
  • This number is a good indication on the number of
    unit tests it will take to achieve full code
    coverage.
  • Lower is typically better however by itself
    cyclomatic complexity is not a very meaningful
    statistic, it is only in the context of the
    problem complexity and the method or class size
    that it can be evaluated.
  • Visual Studio code analysis uses a cyclomatic
    complexity score of 25 as the cutoff for
    recommendation to rewrite or refactor the code.
  • Maintainability Index
  • A value that ranges from 0 to 100 and indicates
    the overall maintainability of the code.
  • The maintainability index is a composite value
    calculated by Visual Studio based on several
    other metrics, including Halstead Volume (which
    factors in the number and use of operands and
    operators), Cyclomatic Complexity and Lines of
    Code
  • A lower number indicates more complex and
    difficult code to maintain.
  • A score of 20 or greater indicates maintainable
    code.
  • Maintainability Index MAX(0,(171 - 5.2
    ln(Halstead Volume) - 0.23 (Cyclomatic
    Complexity) - 16.2 ln(Lines of Code))100 / 171)

8
(No Transcript)
9
Code Analysis
  • When the source code is built VSTS checks a
    broad range of coding rules.
  • The rules are divided into two categories
  • Errors - Errors will cause the build to fail and
    must be corrected before the build can be
    deployed
  • Warnings Warnings are less significant
    violations of the coding rules and will not
    prevent the build from being successfully
    deployed.
  • The code Analysis Rules are grouped into the
    following categories
  • Design Rules
  • Globalization Rules
  • Interoperability Rules
  • Maintainability Rules
  • Mobility Rules
  • Naming Rules
  • Performance Rules
  • Portability Rules
  • Reliability Rules
  • Security Rules
  • Usage Rules

10
(No Transcript)
11
Code Review Process Using VSTS
  • Compile Code With Code Analysis Enabled
  • Unit Test passing with 80 Code Coverage
  • Review Code Metrics and ensure all Classes and
    Methods have
  • A minimum Maintainability Score of 20 or above
  • A Maximum Cyclomatic Complexity of 25
  • Perform a Code Inspection

12
Code Inspection Procedure
  • Four roles of a code inspection team
  • Moderator - The moderator runs the code
    inspection process. The moderator must be a team
    member and not a manager.
  • Reader - The reader looks at the code and
    translates it into an English language
    description of the statements intent.
  • Author This is the developer who wrote the code
    and their role is to provide insight into his
    intentions when those are not clear (which is a
    sign theres a problem with either the code or
    the documentation). The author cannot also be
    the reader editing your own work is fraught with
    risk you see what you thought you wrote, not
    whats on the paper. The same is true for code.
  • Recorder The recorder logs the problems found
    (Ideally input directly into TFS as bugs)

13
Code Inspection Items - Architecture
  • An application with good architecture will have
    most if not all of the following characteristics
  • Easy to maintain maintainability is primarily
    of function of understandability (so bugs are not
    introduced during maintenance) and limited
    impacts of changes (to limit unwanted side
    effects.)
  • Easy to modify requirements will change the
    architecture needs to accept this certainty and
    allow for it.
  • Scalable - A scalable system is one that gets a
    commensurate performance improvement with
    additional hardware.
  • Reusable Code This is similar to data
    normalization but applied to the code rather that
    the data. The underling principle is one rule one
    place.

14
Code Inspections Items - Structure
  • Code Tiers Are the code tiers appropriate,
    consistent, and compliant with existing
    standards.
  • Code Layers Are the Tiers layers correctly, and
    are the Classes and methods in the correct
    location.
  • Encapsulation Are Variations Encapsulated
  • Interfaces Are Interfaces defined appropriately
    and used between layers and for variation.
  • Class coupling Are classes loosely coupled.
  • Out-of-Process Calls, are out of process calls
    course grained and resources released correctly.
  • Error Handling A high percentage of bugs are
    introduced in error handling are catch blocks
    scoped appropriately and are errors re-thrown as
    needed.
  • Memory Management - Are calls to unmanaged code
    wrapped in classes that manage memory correctly.

15
Conclusion
  • To deliver high quality applications affordably
    quality has to be built into the development
    process.
  • The use of the Unit Testing, Code Coverage, Code
    Analysis, and Code Metrics capabilities in VSTS
    in conjunction with Code Inspections can ensure
    this quality at the Architectural, Structural,
    and Implementation levels within the application.
Write a Comment
User Comments (0)
About PowerShow.com