520 likes | 529 Views
Learn effective strategies to control technical debt in an agile environment using continuous inspection. Explore a scalable framework for automated code analysis to enhance code quality and reduce defects. Gain insights from case studies and agile best practices.
E N D
ImplementingZero-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 • Best practices • Lessons learned from 2 case studies • Agile lessons learned • What you can do tomorrow
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
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
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.
What is Continuous Inspection • an approach to running automated code analysis as part of a build in order to find code quality problems
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
Continuous Inspection Tooling • SonarQubewww.sonarqube.org • CAST www.castsoftware.com • Microsoft Visual Studio/Team Foundation Server
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
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
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
Architecture ETL Overview • Extract, transform and load • Match the committer with the quality change
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
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
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
Fast Feedback Bake Code Quality into the Build and Sprint Notificationsin every phase Sprint Code Quality ChangeTechnical DebtOpen Tickets To Fix Debt DailyIntegration Tests Code Quality Champions Personalized CQ Report ContinuousAuto Build Unit TestDeploy Email Code Quality Warnings
Technical Debt Information Radiator • Fast feedback: identify and notify Immediately • Inside the IDE • After the commit • Track until it’s fixed
Fast Feedback 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
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
2. Track Until It’s Fixed • Metric • Submitter • Lead • Reviewer • Class • Sprint • Date
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
Report Weekly Progress by Owner Ratio of bad to good code Weekly progress Current debt
Report Weekly Tech Debt Trends • By project • Or by owner
Best Practices • 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, cont’d • 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
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
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
Reviewers Guard Against Doing the Wrong Thing • Meaningless comments • Unit tests just for coverage that assert nothing • Allow some large case statements
Managing the Debt Rate • Debt rate is about 15% for both projects • Varies widely by developer Monthly debt rate
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
Does bad code cause defects? 10/20 top NPEs predicted Probability =exp( a + b*WEIGHTED_VIOLATIONS + c*COMPLEXITY -d*COVERAGE - e*COMMENT_LINES_DENSITY - f*SCORE)
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
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
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
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
Small Batch Size • Fix the debt as it’s incurred • Don’t let it build up • Minimize tech debt inventory • Static code violations • Code and branch coverage • Complexity management • Circular dependencies • Fan-out reduction
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
Minimize Ceremony • Backlog spreadsheet always available • Morning “warm-up”, fix a little every day • Only open backlog tickets at release or sprint boundaries
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
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
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
How Much Time for a Code Quality Czar? • 12% of a senior dev’r
You Can Maintain Velocity and have Zero Debt Keep the code base maintainable so velocity continues 13% more code per year All with 100% test coverage