Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to be that way.

Noted software expert Robert C. Martin, presents a revolutionary paradigm with Clean Code: A Handbook of Agile Software Craftsmanship. Martin, who has helped bring agile principles from a practitioner’s point of view to tens of thousands of programmers, has teamed up with his colleagues from Object Mentor to distill their best agile practice of cleaning code “on the fly” into a book that will instill within you the values of software craftsman, and make you a better programmer—but only if you work at it.

What kind of work will you be doing? You’ll be reading code—lots of code. And you will be challenged to think about what’s right about that code, and what’s wrong with it. More importantly you will be challenged to reassess your professional values and your commitment to your craft.  

Clean Code is divided into three parts. The first describes the principles, patterns, and practices of writing clean code. The second part consists of several case studies of increasing complexity. Each case study is an exercise in cleaning up code—of transforming a code base that has some problems into one that is sound and efficient. The third part is the payoff: a single chapter containing a list of heuristics and “smells” gathered while creating the case studies. The result is a knowledge base that describes the way we think whenwe write, read, and clean code.
 
Readers will come away from this book understanding
  • How to tell the difference between good and bad code
  • How to write good code and how to transform bad code into good code
  • How to create good names, good functions, good objects, and good classes
  • How to format code for maximum readability
  • How to implement complete error handling without obscuring code logic
  • How to unit test and practice test-driven development
  • What “smells” and heuristics can help you identify bad code
This book is a must for any developer, software engineer, project manager, team lead, or systems analyst with an interest in producing better code.
 
1137736320
Clean Code: A Handbook of Agile Software Craftsmanship
Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to be that way.

Noted software expert Robert C. Martin, presents a revolutionary paradigm with Clean Code: A Handbook of Agile Software Craftsmanship. Martin, who has helped bring agile principles from a practitioner’s point of view to tens of thousands of programmers, has teamed up with his colleagues from Object Mentor to distill their best agile practice of cleaning code “on the fly” into a book that will instill within you the values of software craftsman, and make you a better programmer—but only if you work at it.

What kind of work will you be doing? You’ll be reading code—lots of code. And you will be challenged to think about what’s right about that code, and what’s wrong with it. More importantly you will be challenged to reassess your professional values and your commitment to your craft.  

Clean Code is divided into three parts. The first describes the principles, patterns, and practices of writing clean code. The second part consists of several case studies of increasing complexity. Each case study is an exercise in cleaning up code—of transforming a code base that has some problems into one that is sound and efficient. The third part is the payoff: a single chapter containing a list of heuristics and “smells” gathered while creating the case studies. The result is a knowledge base that describes the way we think whenwe write, read, and clean code.
 
Readers will come away from this book understanding
  • How to tell the difference between good and bad code
  • How to write good code and how to transform bad code into good code
  • How to create good names, good functions, good objects, and good classes
  • How to format code for maximum readability
  • How to implement complete error handling without obscuring code logic
  • How to unit test and practice test-driven development
  • What “smells” and heuristics can help you identify bad code
This book is a must for any developer, software engineer, project manager, team lead, or systems analyst with an interest in producing better code.
 
59.99 In Stock
Clean Code: A Handbook of Agile Software Craftsmanship

Clean Code: A Handbook of Agile Software Craftsmanship

by Robert Martin
Clean Code: A Handbook of Agile Software Craftsmanship

Clean Code: A Handbook of Agile Software Craftsmanship

by Robert Martin

eBook

$59.99 

Available on Compatible NOOK devices, the free NOOK App and in My Digital Library.
WANT A NOOK?  Explore Now

Related collections and offers


Overview

Even bad code can function. But if code isn’t clean, it can bring a development organization to its knees. Every year, countless hours and significant resources are lost because of poorly written code. But it doesn’t have to be that way.

Noted software expert Robert C. Martin, presents a revolutionary paradigm with Clean Code: A Handbook of Agile Software Craftsmanship. Martin, who has helped bring agile principles from a practitioner’s point of view to tens of thousands of programmers, has teamed up with his colleagues from Object Mentor to distill their best agile practice of cleaning code “on the fly” into a book that will instill within you the values of software craftsman, and make you a better programmer—but only if you work at it.

What kind of work will you be doing? You’ll be reading code—lots of code. And you will be challenged to think about what’s right about that code, and what’s wrong with it. More importantly you will be challenged to reassess your professional values and your commitment to your craft.  

Clean Code is divided into three parts. The first describes the principles, patterns, and practices of writing clean code. The second part consists of several case studies of increasing complexity. Each case study is an exercise in cleaning up code—of transforming a code base that has some problems into one that is sound and efficient. The third part is the payoff: a single chapter containing a list of heuristics and “smells” gathered while creating the case studies. The result is a knowledge base that describes the way we think whenwe write, read, and clean code.
 
Readers will come away from this book understanding
  • How to tell the difference between good and bad code
  • How to write good code and how to transform bad code into good code
  • How to create good names, good functions, good objects, and good classes
  • How to format code for maximum readability
  • How to implement complete error handling without obscuring code logic
  • How to unit test and practice test-driven development
  • What “smells” and heuristics can help you identify bad code
This book is a must for any developer, software engineer, project manager, team lead, or systems analyst with an interest in producing better code.
 

Product Details

ISBN-13: 9780135398548
Publisher: Pearson Education
Publication date: 09/30/2025
Series: Robert C. Martin Series
Sold by: Barnes & Noble
Format: eBook
File size: 13 MB
Note: This product may take a few minutes to download.
Age Range: 18 Years

About the Author

Robert C. Martin (Uncle Bob) has been a programmer and software development expert since 1970. He is founder of Uncle Bob Consulting, LLC, and cofounder with his son Micah Martin of The Clean Coders LLC. Martin has published dozens of articles in various trade journals and is a regular speaker at international conferences and trade shows. He is the author of many books, including Agile Software Development: Principles, Patterns, and Practices; UML for Java Programmers; Clean Code; The Clean Coder; Clean Architecture; Clean Agile; Clean Craftsmanship; and Functional Design. Martin served for three years as editor-in-chief of the C++ Report and as the first chairman of the Agile Alliance.

Table of Contents

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 Open–Closed 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

Preface

Which door represents your code? Which door represents your team, or your company? Why are we in that room? Is this just a normal code review or have we found a stream of horrible problems shortly after going live? Are we debugging in a panic, poring over code that we thought worked? Are customers leaving in droves and manager breathing down our necks? How can we make sure we wind up behind the right door when the going gets tough? The answer is: Craftsmanship.

There are two parts to learning craftsmanship: knowledge and work. You must gain the knowledge of principles, patterns, practices, and heuristics that a craftsman knows, and you must also grind that knowledge into your fingers, eyes, and gut by working hard and practicing.

I can teach you the physics of riding a bicycle. Indeed, the classical mathematics is relatively straightforward. Gravity, friction, angular momentum, center of mass, etc., can be demonstrated with less than a page full of equations. Given those formulae I could prove to you that bicycle riding is practical, and give you all the knowledge you needed to make it work. And you'd still fall down the first time you climbed on that bike.

Coding is no different. We could write down all the "feel good" principles of clean code and then trust you to do the work (i.e., let you fall down when you get on the bike), but then what kind of teachers would that make us, and what kind of student would that make you?

No. That's not the way this book is going to work.

Learning to write clean code is hard work. It requires more than just the knowledge of principles and patterns. You must sweat over it. You must practice it yourself, and watch yourself fail.You must watch others practice it and fail. You must see them stumble and retrace their steps. You must see them agonize over decisions, and see the price they pay for making those decisions the wrong way.Be prepared to work hard while reading this book. This is not a "feel good" book that you can read on an airplane and finish before you land. This book will make you work, and work hard. What kind of work will you be doing? You'll be reading code -- lots of code. And you will be challenged to think about what's right about that code, and what's wrong with it. You'll be asked to follow along as we take modules apart and put them back together again. This will take time and effort; but we think it will be worth it. We have divided this book into three parts. The first several chapters describe the principles, patterns, and practices of writing clean code. There is quite a bit of code in these chapters, and they will be challenging to read. They'll prepare you for the second section to come. If you put the book down after reading the first section, good luck to you! The second part of the book is the harder work. It consists of several case studies of ever increasing complexity. Each case study is an exercise in cleaning up some code -- of transforming code that has some problems into code that has fewer problems. The detail in this section is intense. You will have to flip back and forth between the narrative and the code listings. You will have to analyze and understand the code we are working with, and walk through our reasoning for making each change we make. Set aside some time because this should take you days.

The third part of this book is the payoff. It is a single chapter containing a list of heuristics and smells gathered while creating the case studies. As we walked through and cleaned up the code in the case studies, we documented every reason for our actions as a heuristic or smell. We tried to understand our own reactions to the code we were reading and changing, and worked hard to capture why we felt what we felt, and did what we did. The result is a knowledge base that describes the way we think when we write, read, and clean code.

This knowledge base is of limited value if you don't do the work of carefully reading through the case studies in the second part of this book. In those case studies we have carefully annotated each change we made with forward references to the heuristics. These forward references appear in square brackets like this: H22. This lets you see the context in which those heuristics were applied and written! It is not the heuristics themselves that are so valuable, it is the relationship between those heuristics and the discrete decisions we made while cleaning up the code in the case studies.

To further help you with you with those relationships, we have placed a cross reference at the end of the book that shows the page number for every forward reference. You can use it to look up each place where a certain heuristic was applied.

If you read the first and third sections, and skip over the case studies, then you will have read yet another "feel good" book about writing good software. But if you take the time to work through the case studies, following every tiny step, every minute decision. If you put yourself in our place, and force yourself to think along the same paths that we thought, then you will gain a much richer understanding of those principles, patterns, practices, and heuristics. They won't be "feel good" knowledge any more. They'll have been ground into your gut, fingers, and heart. They'll have become part of you in the same way that a bicycle becomes an extension of your will when you have mastered how to ride it.

From the B&N Reads Blog

Customer Reviews