implementing zero-debt continuous inspection in an agile manner

52
Implementing Zero-Debt Continuous Inspection in an Agile Manner A Case Study Brian Chaplin October 8, 2013

Upload: eitan

Post on 22-Feb-2016

43 views

Category:

Documents


0 download

DESCRIPTION

Implementing Zero-Debt Continuous Inspection in an Agile Manner. A Case Study. Brian Chaplin October 8, 2013. Agenda. What is technical debt? What is continuous inspection? A scalable framework to automate technical debt reporting How to control technical debt using the framework - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Implementing Zero-Debt Continuous Inspection in an Agile Manner

ImplementingZero-Debt Continuous Inspection in an Agile MannerA Case Study

Brian ChaplinOctober 8, 2013

Page 2: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Agenda• What is technical debt?• What is continuous inspection?• A scalable framework to automate technical

debt reporting• How to control technical debt using the

framework• Best practices• Lessons learned from 2 case studies

– Agile lessons learned• What you can do tomorrow

Page 3: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Technical Debt Metaphor

• Ward Cunningham at OOPSLA 92 : “Shipping first time code is like going into debt. A little debt speeds development so long as it is paid back promptly with a rewrite...”

• However,– Every minute spent on debt counts as interest

Page 4: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Consequences of Technical Debt

• Product atrophy• Decreased

predictability• Underperformance• Universal frustration• Decreased customer

satisfaction

• Unpredictable tipping point

• Increased time to delivery

• Significant number of defects

• Rising development and support costs

From Essential Scrum, Kenneth S. Rubin

Page 5: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Types of Debt• Naïve

– reckless debt (Fowler 2009), unintentional debt (McConnell 2007), and mess (Martin 2008).

• Unavoidable– Although this debt might be predictable it’s not

preventable because we can’t foresee how the component might evolve

• Strategic– deliberately make a strategic decision to take shortcuts

during product development to achieve an important short-term goal, such as getting a time-sensitive product into the marketplace.

Page 6: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Naïve Technical Debt DefinedCoverage Uncovered conditions

Uncovered linesComplexity Average method complexity

Total class complexityCompliance 140 static code analysis rules

Critical, major, minor weightsDuplication Duplicated linesOrganization Circular dependencies

Design Fan-out, 6

Page 7: Implementing Zero-Debt Continuous Inspection in an Agile Manner

What is Continuous Inspection

• an approach to running automated code analysis as part of a build in order to find code quality problems

Page 8: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Why Continuous Inspection?

• 5. Sustainable development, able to maintain a constant pace

• 9. Continuous attention to technical excellence and good design

• can help reduce the time spent in long, manual code review sessions

Page 9: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Continuous Inspection Tooling

• SonarQube www.sonarqube.org

• CAST www.castsoftware.com

• Microsoft Visual Studio/Team Foundation Server

Page 10: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Automating Continuous Inspection Reporting

• Necessary for large projects–Agile and timely reporting within hours

• Necessary for zero-debt–Architects only have time for the big

issues–Computer handles the smaller quality

defects

Page 11: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Business Context

• Large project, semi-Agile• IT history of past quality initiatives

– OO and pair programming– Automated unit test generation

• Management goal of 80% test coverage• Continuous integration build/deploy

Page 12: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Characteristics of 2 Case StudiesCategory Java

Open SourceC# dot Net

Developers 100 175LOC 2,200,000 1,600,000Commits per day 30 36Classes 14,000 13,000Unit tests, Coverage 41,000 83% 22,000 63%

File changes per day 225 500Technical debt per day 20 50Code quality since 2009 Dec. 2012

Page 13: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Architecture Requirements for Code Quality (CQ) Statistics

• Must come from existing continuous integration process

• Available within 24 hours• Meaningful to developers, leads and

management• Must involve reviewers• Must tie to accountability points

– Leads, reviewers, submitters, project, business function

Page 14: Implementing Zero-Debt Continuous Inspection in an Agile Manner

• Extract, transform and load

• Match the committer with the quality change

Architecture ETL Overview

Page 15: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Architecture Overview• Extract/Transform/Load

(ETL)• Input

– Source code management system (SCM)

– Project management system

– Code quality metrics

• Output– SQL database– Excel pivot table reports– Defect tickets (project

management system)– Email– Ad hoc management

reports– Program scores and

developer contribution

Page 16: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Establish and Maintain the Quality Database

• Guard against corrupted quality data– Test or build failures– Sonar may record lower stats– Rollback a bad build

• Design for mash-ups• Combine code quality with runtime defect

reporting

Page 17: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Maximize Report Flexibility• Enables timely and actionable reporting• Excel pivot table as data-marts• Refreshed Excel reports accessed via Email

hyperlinks or served up by web server

Page 18: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Bake Code Quality into the Build and Sprint

Notificationsin every phase Sprint

Code Quality ChangeTechnical DebtOpen Tickets To Fix DebtDaily

Integration Tests

Code Quality Champions Personalized CQ ReportContinuous

Auto Build Unit Test Deploy

Email Code Quality Warnings 18

Fast Feedback

Page 19: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Technical Debt Information Radiator

1. Fast feedback: identify and notify Immediately

–Inside the IDE–After the commit

2. Track until it’s fixed

Page 20: Implementing Zero-Debt Continuous Inspection in an Agile Manner

1. Notify Immediately• Email each debt violation within hours

– After each continuous inspection build• 3 times a day or after every CI build

• Notify both committer and code reviewer• Daily contribution

– Best contributors summary– Personalized contribution detail to each

committer• Hyperlink to more reports and wiki

– Direct Sonar hyperlink to the degraded file

Fast Feedback

Page 21: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Project ID

Change ID

Prog. Name

UncoveredLines or Branches

Static Code

Analysis Debt

Excess Complexity

Class Function

ticket1 580932 4/18/2013 Class1 9 9

ticket1 580902 4/18/2013 Class3 4 0 14 2.8

ticket1 580902 4/18/2013 Class5 23 0 13 2.6

Submission Warning(s)You are receiving this message because even though the code quality may have been enhanced, the submission(s) below have decreased the code quality (coverage, compliance, and/or uncovered complexity) or they didn't meet the standards for a new class. Please review these submissions with your reviewer and take the appropriate action.

Sample Violation Email

Page 22: Implementing Zero-Debt Continuous Inspection in an Agile Manner

• Metric• Submitter• Lead• Reviewer• Class• Sprint• Date

2. Track Until It’s

Fixed

Page 23: Implementing Zero-Debt Continuous Inspection in an Agile Manner

2. Track Debt Until It’s Fixed

Page 24: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Making Technical Debt Visible

• Estimate the cost of remediation• Assign owner• Report weekly progress by owner• Report trends• Monetize it, various methods

– SQALE (Software Quality Assessment based on Lifecycle Expectations) from Inspearit, Jean-Louis Letouzey

Page 25: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Monetize the DebtEstimated Remediation Costs

Cost Activity12 minutes To unit test uncovered branch or

line6 minutes To fix static code analysis violation8 hours To split a class that is too complex30 minutes To split a method that is too

complex2 hours To eliminate a block of duplicated

code

Page 26: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Current debt

Ratio of bad to good code

Weekly progress

Report Weekly Progress by Owner

Page 27: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Report Weekly Tech Debt Trends

• By project• Or by

owner

Page 28: Implementing Zero-Debt Continuous Inspection in an Agile Manner

• Staff a code quality desk–Knowledge clearinghouse

• Use code reviewers• Stabilize build and project structure• Establish static code analysis rules and

rarely change them

Best Practices

Page 29: Implementing Zero-Debt Continuous Inspection in an Agile Manner

• Developers must be able to clear unfixable debt from the tracking report

• Run the ETL at least daily• Keep the database accurate• Track both contribution and debt• Recognize code quality champions• Use uncovered line/branch count not

percentage

Best Practices, cont’d

Page 30: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Allow for Exclusions, False Positives

• Integrations, class rename, code moves

• Classes exempted from quality–Registries–Test support

• Unfixable debt–Unreachable test

cases–Exceptions to the

metrics standard–Static analysis false

positives• 0.5% are excluded

Page 31: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Case Study Lessons Learned• Communicate the benefits of code quality

– Maintainability– Less runtime defects, explain carefully– Working with a net

• Help new developers with un-testable code– Train and mentor– Consider refactoring to testable code first, then

write the test

Page 32: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Reviewers Guard Against Doing the Wrong Thing

• Meaningless comments• Unit tests just for coverage that assert

nothing• Allow some large case statements

Page 33: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Too Busy to Keep Debt Down?

Page 34: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Monthly debt rate

Managing the Debt

Rate

• Debt rate is about 15% for both projects

• Varies widely by developer

Page 35: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Techniques to Keep the Debt Rate Low

• Immediate feedback• Open defect tickets at

key points• Train• Assist developers one

on one• Encourage re-

factoring to write testable code

• Code a little, test a little

• Keep management aware

• Continually monitor, don’t let it get out of hand

• Recognize the champions

Page 36: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Count 282 8,447Average value NPE Not Function complexity 2.90 1.88 Lcom4 1.98 1.14 Weighted violations 7.52 2.70 Complexity 66 11 Coverage 85% 83% Duplicated lines 1.99 5.61 Comment lines density 28% 32% Statements 144 25 Score 1.53 1.73 Fan-out 9.45 3.16

Probability =exp( a + b*WEIGHTED_VIOLATIONS + c*COMPLEXITY -d*COVERAGE -

e*COMMENT_LINES_DENSITY - f*SCORE)

10/20 top NPEs

predicted

probability

class name CXTY SCORE

100%class1 528 1.13100%class2 523 1.12

99%class3 464 0.8999%class4 523 1.2599%class5 523 1.4598%class6 369 1.0796%class7 345 1.1896%class8 341 1.3395%class9 399 0.9595%class10 385 0.8393%class11 305 1.0592%class12 372 1.2491%class13 279 1.3290%class14 416 1.1288%class15 263 1.0288%class16 328 1.0287%class17 318 1.0986%class18 428 1.1085%class19 316 0.8984%class20 236 1.22

Does bad code cause defects?

Page 37: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Implement the “Boy Scout rule”

• Encourage Code Quality Improvement On Every Commit

• Score the program’s improvement• Score the committer’s improvement• Recognize the contributors• Ensure the numbers are used properly

Page 38: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Agile Lessons Learned

Page 39: Implementing Zero-Debt Continuous Inspection in an Agile Manner

When and How to Create Debt Backlog Items

• Detailed appropriately– By metric, program file,

developer

• Emergent– At release code branch– Move to later Sprints as

necessary

• Estimated– Use Sonar tech debt

estimate

• Prioritize by– Complexity– Unit tests– Static code

Page 40: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Keep the Pressure Off

• Be positive!• Manage debt informally as sprint

issues• Use TDD and other techniques as

productivity aids• Interpret the contribution metrics

correctly

Page 41: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Fast Feedback

• Reviewers work with submitters to fix same day

• Quick emails with links to more information

• Allow developers to correct immediately after receiving an email

Page 42: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Small Batch Size

• Fix the debt as it’s incurred

• Don’t let it build up

• Minimize tech debt inventory1. Static code violations2. Code and branch

coverage3. Complexity

management4. Circular

dependencies5. Fan-out reduction

Page 43: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Individual vs. Group Accountability

• Idle work vs. idle workers–Attack the most significant debt first

• Fix your own debt quickly–You know the code best

• Fix debt in the code you’re working on–Leave it cleaner than you found it

Page 44: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Minimize Ceremony

• Backlog spreadsheet always available• Morning “warm-up”, fix a little every

day• Only open backlog tickets at release

or sprint boundaries

Page 45: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Code Quality Take-away Messages

Page 46: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Quality Motivates and Enhances Productivity

• Tom DeMarco & Timothy Lister, Peopleware: “Quality, …, is a means to higher productivity”

• Defect removal #1 cause of productivity loss

• Programmers are motivated by emphasis on code quality

Page 47: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Implement CQ Continuous Inspection• Establish CQ point of

accountability• Promote CQ• Track technical debt

– Require remediation• Scales to large projects

– Multi-branch– Multi-language

• Target the reports– End of Sprint or

production release branch

– By lead, committer, reviewer

– Commit quality trend

Page 48: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Embed a Code Quality Expert on the Team

• Unit testing techniques– Mocks– Corner cases

• When to override the warnings• When to clear, not fix, debt• Safe re-factoring

Page 49: Implementing Zero-Debt Continuous Inspection in an Agile Manner

How Much Time for a Code Quality Czar?• 12% of a senior dev’r

cq48%

lead35%

devr9% mgr

5%build

er2%

Roles

Effort breakdownRole task Total

Code Quality Czar   

 

monitor technical debt 13%clear unfixable debt 10%mentor/assist 6%scoring 5%monitor dev branches 4%manual db update/fix/check 3%ad hoc reporting 2%email warning help desk 2%standards setting 2%investigate numbers/database 1%

 Lead developers

report review 16%performance appraisal 13%presentations 4%train 1%trend analysis 1%

Code coding 5%  write SQL 4%Manage awareness 2%  inform/escalate 2%  sell 2%Build sonar 2%

Page 50: Implementing Zero-Debt Continuous Inspection in an Agile Manner

13% more code per yearAll with 100% test

coverage

Keep the code base maintainable so velocity continues

You Can Maintain Velocity and have Zero Debt

Page 51: Implementing Zero-Debt Continuous Inspection in an Agile Manner

What Can You Do Tomorrow?• Implement a code quality dashboard

– Sonar– MS Visual Studio or Eclipse CQ plugin

• Require unit testing• Peer review at check-in• Break the CI build if quality decreases

– Coverage drops below threshold– Critical or major static analysis violations

Page 52: Implementing Zero-Debt Continuous Inspection in an Agile Manner

Thank You!

Brian [email protected]: bchaplin1 NoTechnicalDebt.com