Table Of ContentEarly praise for Beyond Legacy Code
Beyond Legacy Code presents a fresh perspective on the modern software devel-
opment process. Engineers will find solutions to their day-to-day challenges. Non-
engineers will gain an appreciation for the challenges and difficulties of making
software.
➤ Stas Zvinyatskovsky
Senior Principal Software Architect, Yahoo
David helps us see how we got where we are. He gives us things to do that will
help us. He gives us deep matters to think about. This book is a gift to people
who care about software. Take advantage of it.
➤ Ron Jeffries
RonJeffries.com
If you feel stuck and powerless to improve your software delivery process, this
book will offer years of experience distilled in just a few core ideas. This is a great
book for anyone starting on a journey toward frequent iterative delivery, and for
those people who tried adopting an agile process and failed to get the big benefits.
➤ Gojko Adzic
Partner, Neuri Consulting LLP
This book provides great discussion on what things I can do to make customers
happy and also to keep them happy as their needs change.
➤ David Weiser
Software Engineer, Moz
It’s a good read for any developer or manager, working on any type of code in any
company.
➤ Troy Magennis
Author of Forecasting and Simulating Software Development Projects, CEO Fo-
cused Objective
David’s explanations are so clear I am hopeful even managers of development
teams and leaders running companies who build custom software will pick up
this book and understand these practices that allow us to build software that is
economical to own, maintain, and enhance.
➤ Jim Fiolek
Software Architect, Black Knight Financial Services
Throughout the book there were points that gave me a sense of relief—where I
would think if only we could get people to follow these few principles our life, and
software, would be so much easier and less stressful.
➤ Nick Capito
Director of Software Engineering, Unboxed Technology
We fight to make every line of code we write part of a real live product. Find out
how that fight sometimes leads us astray. Find out how to make you and your
team much more productive in building real live products that customers want
now AND tomorrow.
➤ Michael Hunter
Geek, Hacker, Principal Engineer, Architect
Beyond Legacy Code
Nine Practices to Extend the Life
(and Value) of Your Software
David Scott Bernstein
The Pragmatic Bookshelf
Dallas, Texas • Raleigh, North Carolina
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The Pragmatic
Programmers, LLC was aware of a trademark claim, the designations have been printed in
initial capital letters or in all capitals. The Pragmatic Starter Kit, The Pragmatic Programmer,
Pragmatic Programming, Pragmatic Bookshelf, PragProg and the linking g device are trade-
marks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher assumes
no responsibility for errors or omissions, or for damages that may result from the use of
information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team create
better software and have more fun. For more information, as well as the latest Pragmatic
titles, please visit us at https://pragprog.com.
The team that produced this book includes:
Jacquelyn Carter (editor)
Potomac Indexing, LLC (index)
Liz Welch (copyedit)
Dave Thomas (layout)
Janet Furlow (producer)
Ellie Callahan (support)
For international rights, please contact [email protected].
Copyright © 2015 The Pragmatic Programmers, LLC.
All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
in any form, or by any means, electronic, mechanical, photocopying, recording, or otherwise,
without the prior consent of the publisher.
Printed in the United States of America.
ISBN-13: 978-1-68050-079-0
Encoded using the finest acid-free high-entropy binary digits.
Book version: P1.0—August 2015
Contents
Foreword . . . . . . . . . . . . . . xi
Acknowledgments . . . . . . . . . . . xv
Introduction . . . . . . . . . . . . xvii
Part I — The Legacy Code Crisis
1. Something’s Wrong . . . . . . . . . . . 3
What Is Legacy Code? 5
Down the Waterfall 7
Playing All or Nothing 8
Why Waterfall Doesn’t Work 9
When “Process” Becomes “Busy Work” 11
Concrete Management 13
Here Be Dragons 13
Estimating Unknowns 15
An Industry of Amateurs 16
Retrospective 18
2. Out of CHAOS . . . . . . . . . . . . 19
The CHAOS Report 19
Refuting Standish 21
Why Projects Fail 23
The Cost of Failure 27
Retrospective 30
3. Smart People, New Ideas . . . . . . . . . . 33
Enter Agile 33
Smaller Is Better 35
Implementing Agile 36
Contents • vi
Balancing Art and Craft 38
Agile Crosses the Chasm 40
Demand Technical Excellence 40
Retrospective 41
Part II — Nine Practices to Extend the Life (and Value) of Your Software
4. The Nine Practices . . . . . . . . . . . 45
What Experts Know 47
Shu-Ha-Ri 48
First Principles 49
To Be a Principle 51
To Be a Practice 51
Principles Guide Practices 52
Anticipate or Accommodate 53
Defining “Good” in Software 54
Why Nine Practices 56
Retrospective 57
5. Practice 1: Say What, Why, and for Whom Before How . . 59
Don’t Say How 60
Turn “How” Into “What” 61
Have a Product Owner 63
Stories Tell What, Why, and for Whom 64
Set Clear Criteria for Acceptance Tests 67
Automate Acceptance Criteria 68
Let’s Get Practical 69
Retrospective 72
6. Practice 2: Build in Small Batches . . . . . . . 73
Tell Smaller Lies 74
Be Willing to Flex 75
Cadence Dictates Process 77
Smaller Is Better 79
Divide and Conquer 80
Shorten Feedback Cycles 82
Speed Up the Build 83
Respond to Feedback 85
Build a Backlog 86
Break Stories Into Tasks 87
Contents • vii
Think Outside the Time Box 88
Manage Scope 89
Let’s Get Practical 91
Retrospective 94
7. Practice 3: Integrate Continuously . . . . . . . 97
Establish the Heartbeat of a Project 98
Know the Difference Between Done, Done-Done, and
Done-Done-Done 99
Practice Continuous Deployability 99
Automate the Build 101
Integrate Early and Often 103
Take the First Step 103
Let’s Get Practical 104
Retrospective 108
8. Practice 4: Collaborate . . . . . . . . . . 109
Extreme Programming 111
Communication and Collaboration 112
Pair Program 113
Buddy Program 119
Spike, Swarm, and Mob 120
Research Unknowns in Time Boxes 121
Schedule Code Reviews and Retrospectives 122
Amplify Learning and Spread Knowledge 123
Always Strive to Be Mentoring and Mentored 124
Let’s Get Practical 125
Retrospective 128
9. Practice 5: Create CLEAN Code . . . . . . . . 129
Quality Code Is Cohesive 130
Quality Code Is Loosely Coupled 132
Quality Code Is Encapsulated 134
Quality Code Is Assertive 136
Quality Code Is Nonredundant 138
Code Qualities Guide Us 140
Increase Quality Today to Increase Velocity Tomorrow 141
Let’s Get Practical 142
Retrospective 146
Contents • viii
10. Practice 6: Write the Test First . . . . . . . . 147
The Things We Call Tests 148
Quality Assurance 150
Write Good Tests 152
TDD Gives Rapid Feedback 155
TDD Supports Refactoring 155
Write Testable Code 156
TDD Can Fail 158
Introduce TDD to a Team 159
Become Test Infected 159
Let’s Get Practical 160
Retrospective 163
11. Practice 7: Specify Behaviors with Tests . . . . . 165
Red Bar/Green Bar/Refactor 166
An Example of Specifying Behaviors Test-First 167
Introducing Constraints 171
What I Created 173
Tests Are Specifications 176
Be Complete 176
Make Each Test Unique 178
Cover Code with Tests 178
Bugs Are Missing Tests 179
Test Workflows with Mocks 180
Create a Safety Net 180
Let’s Get Practical 181
Retrospective 184
12. Practice 8: Implement the Design Last . . . . . . 185
Impediments to Changeability 185
Sustainable Development 188
Coding vs. Cleaning 189
Software Is Read More than It’s Written 190
Program by Intention 190
Reduce Cyclomatic Complexity 192
Separate Use from Creation 193
Emergent Design 195
Let’s Get Practical 196
Retrospective 199