Clean Code A Handbook of Agile Software Craftsmanship

  • ISBN13:


  • ISBN10:


  • Edition: 1st
  • Format: Paperback
  • Copyright: 8/1/2008
  • Publisher: Prentice Hall

Note: Supplemental materials are not guaranteed with Rental or Used book purchases.

Purchase Benefits

  • Free Shipping On Orders Over $59!
    Your order must be $59 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • Get Rewarded for Ordering Your Textbooks! Enroll Now
  • We Buy This Book Back!
    In-Store Credit: $4.20
    Check/Direct Deposit: $4.00
List Price: $49.99 Save up to $17.50
  • Rent Book $32.49
    Add to Cart Free Shipping


Supplemental Materials

What is included with this book?

  • The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.
  • The Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.


Even bad code can function. But if code isnrs"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 doesnrs"t have to be that way. Noted software expert Robert C. Martin presents a revolutionary paradigm withClean Code: A Handbook of Agile Software Craftsmanship. Martin 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 a software craftsman and make you a better programmer-but only if you work at it. What kind of work will you be doing? Yours"ll be reading code-lots of code. And you will be challenged to think about whatrs"s right about that code, and whatrs"s wrong with it. More importantly, you will be challenged to reassess your professional values and your commitment to your craft. Clean Codeis 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 when we 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 This book is a must for any developer, software engineer, project manager, team lead, or systems analyst with an interest in producing better code.

Author Biography

Robert C. “Uncle Bob” Martin has been a software professional since 1970 and an international software consultant since 1990. He is founder and president of Object Mentor, Inc., a team of experienced consultants who mentor their clients worldwide in the fields of C++, Java, C#, Ruby, OO, Design Patterns, UML, Agile Methodologies, and eXtreme programming.

Table of Contents

Forewordp. xix
Introductionp. xxv
On the Coverp. xxix
Clean Codep. 1
There Will Be Codep. 2
Bad Codep. 3
The Total Cost of Owning a Messp. 4
Schools of Thoughtp. 12
We Are Authorsp. 13
The Boy Scout Rulep. 14
Prequel and Principlesp. 15
Conclusionp. 15
Bibliographyp. 15
Meaningful Namesp. 17
Introductionp. 17
Use Intention-Revealing Namesp. 18
Avoid Disinformationp. 19
Make Meaningful Distinctionsp. 20
Use Pronounceable Namesp. 21
Use Searchable Namesp. 22
Avoid Encodingsp. 23
Avoid Mental Mappingp. 25
Class Namesp. 25
Method Namesp. 25
Don't Be Cutep. 26
Pick One Word per Conceptp. 26
Don't Punp. 26
Use Solution Domain Namesp. 27
Use Problem Domain Namesp. 27
Add Meaningful Contextp. 27
Don't Add Gratuitous Contextp. 29
Final Wordsp. 30
Functionsp. 31
Small!p. 34
Do One Thingp. 35
One Level of Abstraction per Functionp. 36
Switch Statementsp. 37
Use Descriptive Namesp. 39
Function Argumentsp. 40
Have No Side Effectsp. 44
Command Query Separationp. 45
Prefer Exceptions to Returning Error Codesp. 46
Don't Repeat Yourselfp. 48
Structured Programmingp. 48
How Do You Write Functions Like This?p. 49
Conclusionp. 49
SetupTeardownIncluderp. 50
Bibliographyp. 52
Commentsp. 53
Comments Do Not Make Up for Bad Codep. 55
Explain Yourself in Codep. 55
Good Commentsp. 55
Bad Commentsp. 59
Bibliographyp. 74
Formattingp. 75
The Purpose of Formattingp. 76
Vertical Formattingp. 76
Horizontal Formattingp. 85
Team Rulesp. 90
Uncle Bob's Formatting Rulesp. 90
Objects and Data Structuresp. 93
Data Abstractionp. 93
Data/Object Anti-Symmetryp. 95
The Law of Demeterp. 97
Data Transfer Objectsp. 100
Conclusionp. 101
Bibliographyp. 101
Error Handlingp. 103
Use Exceptions Rather Than Return Codesp. 104
Write Your Try-Catch-Finally Statement Firstp. 105
Use Unchecked Exceptionsp. 106
Provide Context with Exceptionsp. 107
Define Exception Classes in Terms of a Caller's Needsp. 107
Define the Normal Flowp. 109
Don't Return Nullp. 110
Don't Pass Nullp. 111
Conclusionp. 112
Bibliographyp. 112
Boundariesp. 113
Using Third-Party Codep. 114
Exploring and Learning Boundariesp. 116
Learning log4jp. 116
Learning Tests Are Better Than Freep. 118
Using Code That Does Not Yet Existp. 118
Clean Boundariesp. 120
Bibliographyp. 120
Unit Testsp. 121
The Three Laws of TDDp. 122
Keeping Tests Cleanp. 123
Clean Testsp. 124
One Assert per Testp. 130
F.I.R.S.Tp. 132
Conclusionp. 133
Bibliographyp. 133
Classesp. 135
Class Organizationp. 136
Classes Should Be Small!p. 136
Organizing for Changep. 147
Bibliographyp. 151
Systemsp. 153
How Would You Build a City?p. 154
Separate Constructing a System from Using Itp. 154
Scaling Upp. 157
Java Proxiesp. 161
Pure Java AOP Frameworksp. 163
AspectJ Aspectsp. 166
Test Drive the System Architecturep. 166
Optimize Decision Makingp. 167
Use Standards Wisely, When They Add Demonstrable Valuep. 168
Systems Need Domain-Specific Languagesp. 168
Conclusionp. 169
Bibliographyp. 169
Emergencep. 171
Getting Clean via Emergent Designp. 171
Simple Design Rule 1: Runs All the Testsp. 172
Simple Design Rules 2-4: Refactoringp. 172
No Duplicationp. 173
Expressivep. 175
Minimal Classes and Methodsp. 176
Conclusionp. 176
Bibliographyp. 176
Concurrencyp. 177
Why Concurrency?p. 178
Challengesp. 180
Concurrency Defense Principlesp. 180
Know Your Libraryp. 182
Know Your Execution Modelsp. 183
Beware Dependencies Between Synchronized Methodsp. 185
Keep Synchronized Sections Smallp. 185
Writing Correct Shut-Down Code Is Hardp. 186
Testing Threaded Codep. 186
Conclusionp. 190
Bibliographyp. 191
Successive Refinementp. 193
Table of Contents provided by Publisher. All Rights Reserved.


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 managers breathing down our necks? How can we make sure we wind up behind therightdoor 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, and so forth, 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 (in other words, 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 becausethis 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 desribes the way we think when we write, read, and clean code.This knowledge base is of limited v

Rewards Program

Write a Review