Foreword xix
Introduction xxv
Introduction (from Long Ago) xxix
About the Author xxxi
Chapter 1: Clean Code 1
There Will Be Code 2
Bad Code 3
The Art of Clean Code 5
Putting All This Together 9
We Read More Than We Write 13
The Boy Scout Rule 14
Part I: Code 17
Chapter 2: Clean That Code! 19
The Cleaning Process 30
Conclusion 37
Postscript: Future Bob Playing with Grok3 37
Postscript Conclusion 40
Chapter 3: First Principles 41
Everything Small, Well Named, Organized, and Ordered 42
A More Significant Example 44
A Final Thought 68
Chapter 4: Meaningful Names 71
Use Intention-Revealing Names 72
Final Words 87
Chapter 5: Comments 89
Compensating for Failure 90
Good Comments 92
Bad Comments 97
Conclusion 115
Chapter 6: Formatting 117
The Purpose of Formatting 118
Vertical Formatting 118
Horizontal Formatting 127
Team Rules 132
Uncle Bob's Formatting Rules 133
Chapter 7: Clean Functions 137
Small! 138
Reading Code from Top to Bottom: The Stepdown Rule 140
Switch Statements 142
Clean Functions: A Deeper Look 144
Conclusion 157
Chapter 8: Function Heuristics 159
Function Arguments 159
Command Query Separation 164
Prefer Exceptions to Returning Error Codes 165
DRY: Don't Repeat Yourself 169
Side Effects 177
Structured Programming 181
This Is Too Much to Constantly Keep in Mind 183
Conclusion 184
Chapter 9: The Clean Method 185
Make It Right 186
Example 188
Conclusion 210
Chapter 10: One Thing 211
Extract Method Refactoring 212
What Are Large Functions Anyway? 217
Conclusion 239
Chapter 11: Be Polite 241
The Newspaper Metaphor 243
The Stepdown Rule: Once Again 245
The Abstraction Roller Coaster 246
This Is How We Write, but Not How We Want to Read 246
Chapter 12: Objects and Data Structures 249
What Is an Object? 250
Data Abstraction 251
Data/Object Antisymmetry 252
The Law of Demeter 255
Data Transfer Objects 258
Switch Statements 260
The OO/Procedural Trade-off 264
But What About Performance? 265
Conclusion 265
Chapter 13: Clean Classes 267
Classes and Modules versus Files 267
What Should a Class Contain? 268
Chapter 14: Testing Disciplines 289
Discipline 1: Test-Driven Development (TDD) 291
Discipline 2: Test && Commit || Revert (TCR) 292
Discipline 3: Small Bundles 293
Design 293
Discipline 294
Keeping Tests Clean 299
Tests Enable the -ilities 300
Chapter 15: Clean Tests 303
Domain-Specific Testing Language 307
F.I.R.S.T. 310
Test Design 311
Conclusion 311
Chapter 16: Acceptance Testing 313
The Acceptance Testing Discipline 314
Conclusion 316
Chapter 17: AIs, LLMs, and God Knows What 317
Programming by Prompt 319
Conclusion 328
Part II: Design 329
Chapter 18: Simple Design 331
YAGNI 333
Covered by Tests 333
Maximize Expression 334
Minimize Duplication 337
Chapter 19: The SOLID Principles 341
SRP: The Single Responsibility Principle 343
OCP: The OpenClosed Principle 347
LSP: The Liskov Substitution Principle 351
ISP: The Interface Segregation Principle 354
DIP: The Dependency Inversion Principle 356
Chapter 20: Component Principles 363
Components 364
A Brief History of Components 364
Component Cohesion 368
Component Coupling 373
Conclusion 387
Chapter 21: Continuous Design 389
Continuous Change 390
Continuous Design 391
Sailing on the Four Cs of Continuous Design 392
When Else Do We Design? 420
Chapter 22: Concurrency 423
Why Concurrency? 424
Concurrency Defense Principles 427
2025 Update and Report from the Field 437
Conclusion 442
Part III: Architecture 443
Chapter 23: The Two Values of Software 445
Keeping Options Open 446
Chapter 24: Independence 449
Use Cases 450
Operation 450
Development 451
Deployment 451
Leaving Options Open 451
Chapter 25: Architectural Boundaries 453
What Lines Do You Draw, and When? 454
Plug-in Architecture 456
Case Study: FitNesse 457
Conclusion 459
Chapter 26: Clean Boundaries 461
Third-Party IoT Framework: Lots o' Boundaries 462
UI/Application Boundary 466
Clean Boundaries 474
Chapter 27: The Clean Architecture 475
The Dependency Rule 476
Conclusion 481
Part IV: Craftmanship 483
"A Great Number" 484
Eight Decades 484
The Oath 492
Chapter 28: Harm 495
No Harm to Society 496
Harm to Function 497
No Harm to Structure 499
Soft 500
Tests 501
Chapter 29: No Defect in Behavior or Structure 503
Making It Right 504
Programmers Are Stakeholders 507
Do Your Best 508
Chapter 30: Repeatable Proof 511
Dijkstra 511
Structured Programming 514
Functional Decomposition 516
Test-Driven Development et al. 517
Chapter 31: Small Cycles 519
The History of Source Code Control 519
Continuous Integration 524
Branches versus Toggles 525
Continuous Deployment 527
Continuous Build 528
Chapter 32: Relentless Improvement 529
Test Coverage 529
Mutation Testing 530
Semantic Stability 530
Cleaning 531
Creations 531
Chapter 33: Maintain High Productivity 533
Viscosity 533
Managing Distractions 535
Time Management 538
Chapter 34: Work as a Team 539
Collaborative Programming 539
Open/Virtual Office 540
Chapter 35: Estimate Honestly and Fairly 543
Lies 544
Honesty, Accuracy, Precision 544
Lessons from Me 545
Accuracy and Precision 547
Aggregation 548
Honesty 549
Pressure 550
Chapter 36: Respect for Fellow Programmers 553
Chapter 37: Never Stop Learning 555
Afterword 557
Appendix: The Clean Code Debate 561
Introductions 562
Method Length 563
Method Length Summary 575
Comments 576
Comments Summary 590
John's Rewrite of PrimeGenerator 591
A Tale of Two Programmers 596
Bob's Rewrite of PrimeGenerator2 599
Test-Driven Development 603
TDD Summary 612
Closing Remarks 613
Bibliography 615
Index 619