Clean Code: A Handbook of Agile Software Craftsmanship

Book description

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.

Related Learning

Video: Clean Code Fundamentals (Clean Coders Video Series)
Books: Clean Coder, Clean Architecture, Clean Agile, Clean Craftsmanship
Live Courses: See upcoming live courses by Uncle Bob

Noted software expert Robert C. Martin presents a revolutionary paradigm with Clean 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? 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 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.

Table of contents

  1. Cover Page
  2. Series Page
  3. Title Page
  4. Copyright Page
  5. Dedication
  6. Contents
  7. Foreword
  8. Introduction
  9. On the Cover
  10. Chapter 1: Clean Code
    1. There Will Be Code
    2. Bad Code
    3. The Total Cost of Owning a Mess
    4. Schools of Thought
    5. We Are Authors
    6. The Boy Scout Rule
    7. Prequel and Principles
    8. Conclusion
    9. Bibliography
  11. Chapter 2: Meaningful Names
    1. Introduction
    2. Use Intention-Revealing Names
    3. Avoid Disinformation
    4. Make Meaningful Distinctions
    5. Use Pronounceable Names
    6. Use Searchable Names
    7. Avoid Encodings
    8. Avoid Mental Mapping
    9. Class Names
    10. Method Names
    11. Don’t Be Cute
    12. Pick One Word per Concept
    13. Don’t Pun
    14. Use Solution Domain Names
    15. Use Problem Domain Names
    16. Add Meaningful Context
    17. Don’t Add Gratuitous Context
    18. Final Words
  12. Chapter 3: Functions
    1. Small!
    2. Do One Thing
    3. One Level of Abstraction per Function
    4. Switch Statements
    5. Use Descriptive Names
    6. Function Arguments
    7. Have No Side Effects
    8. Command Query Separation
    9. Prefer Exceptions to Returning Error Codes
    10. Don’t Repeat Yourself
    11. Structured Programming
    12. How Do You Write Functions Like This?
    13. Conclusion
    14. SetupTeardownIncluder
    15. Bibliography
  13. Chapter 4: Comments
    1. Comments Do Not Make Up for Bad Code
    2. Explain Yourself in Code
    3. Good Comments
    4. Bad Comments
    5. Bibliography
  14. Chapter 5: Formatting
    1. The Purpose of Formatting
    2. Vertical Formatting
    3. Horizontal Formatting
    4. Team Rules
    5. Uncle Bob’s Formatting Rules
  15. Chapter 6: Objects and Data Structures
    1. Data Abstraction
    2. Data/Object Anti-Symmetry
    3. The Law of Demeter
    4. Data Transfer Objects
    5. Conclusion
    6. Bibliography
  16. Chapter 7: Error Handling
    1. Use Exceptions Rather Than Return Codes
    2. Write Your Try-Catch-Finally Statement First
    3. Use Unchecked Exceptions
    4. Provide Context with Exceptions
    5. Define Exception Classes in Terms of a Caller’s Needs
    6. Define the Normal Flow
    7. Don’t Return Null
    8. Don’t Pass Null
    9. Conclusion
    10. Bibliography
  17. Chapter 8: Boundaries
    1. Using Third-Party Code
    2. Exploring and Learning Boundaries
    3. Learning log4j
    4. Learning Tests Are Better Than Free
    5. Using Code That Does Not Yet Exist
    6. Clean Boundaries
    7. Bibliography
  18. Chapter 9: Unit Tests
    1. The Three Laws of TDD
    2. Keeping Tests Clean
    3. Clean Tests
    4. One Assert per Test
    5. F.I.R.S.T.
    6. Conclusion
    7. Bibliography
  19. Chapter 10: Classes
    1. Class Organization
    2. Classes Should Be Small!
    3. Organizing for Change
    4. Bibliography
  20. Chapter 11: Systems
    1. How Would You Build a City?
    2. Separate Constructing a System from Using It
    3. Scaling Up
    4. Java Proxies
    5. Pure Java AOP Frameworks
    6. AspectJ Aspects
    7. Test Drive the System Architecture
    8. Optimize Decision Making
    9. Use Standards Wisely, When They Add Demonstrable Value
    10. Systems Need Domain-Specific Languages
    11. Conclusion
    12. Bibliography
  21. Chapter 12: Emergence
    1. Getting Clean via Emergent Design
    2. Simple Design Rule 1: Runs All the Tests
    3. Simple Design Rules 2–4: Refactoring
    4. No Duplication
    5. Expressive
    6. Minimal Classes and Methods
    7. Conclusion
    8. Bibliography
  22. Chapter 13: Concurrency
    1. Why Concurrency?
    2. Challenges
    3. Concurrency Defense Principles
    4. Know Your Library
    5. Know Your Execution Models
    6. Beware Dependencies Between Synchronized Methods
    7. Keep Synchronized Sections Small
    8. Writing Correct Shut-Down Code Is Hard
    9. Testing Threaded Code
    10. Conclusion
    11. Bibliography
  23. Chapter 14: Successive Refinement
    1. Args Implementation
    2. Args: The Rough Draft
    3. String Arguments
    4. Conclusion
  24. Chapter 15: JUnit Internals
    1. The JUnit Framework
    2. Conclusion
  25. Chapter 16: Refactoring SerialDate
    1. First, Make It Work
    2. Then Make It Right
    3. Conclusion
    4. Bibliography
  26. Chapter 17: Smells and Heuristics
    1. Comments
    2. Environment
    3. Functions
    4. General
    5. Java
    6. Names
    7. Tests
    8. Conclusion
    9. Bibliography
  27. Appendix A: Concurrency II
    1. Client/Server Example
    2. Possible Paths of Execution
    3. Knowing Your Library
    4. Dependencies Between Methods Can Break Concurrent Code
    5. Increasing Throughput
    6. Deadlock
    7. Testing Multithreaded Code
    8. Tool Support for Testing Thread-Based Code
    9. Conclusion
    10. Tutorial: Full Code Examples
  28. Appendix B: org.jfree.date.SerialDate
  29. Appendix C: Cross References of Heuristics
  30. Epilogue
  31. Index

Product information

  • Title: Clean Code: A Handbook of Agile Software Craftsmanship
  • Author(s): Robert C. Martin
  • Release date: August 2008
  • Publisher(s): Pearson
  • ISBN: 9780136083238