Clean code A handbook of agile software craftsmanship

Robert C. Martin

Book - 2009

Saved in:

2nd Floor Show me where

005.1/Martin
0 / 1 copies available
Location Call Number   Status
2nd Floor 005.1/Martin Due Dec 12, 2024
Subjects
Published
Upper Saddle River, NJ : Prentice Hall c2009.
Language
English
Main Author
Robert C. Martin (-)
Physical Description
xxix, 431 p. : ill. ; 24 cm
Bibliography
Includes bibliographical references and index.
ISBN
9780132350884
  • Foreword
  • Introduction
  • On the Cover
  • Chapter 1. Clean Code
  • There Will Be Code
  • Bad Code
  • The Total Cost of Owning a Mess
  • Schools of Thought
  • We Are Authors
  • The Boy Scout Rule
  • Prequel and Principles
  • Conclusion
  • Bibliography
  • Chapter 2. Meaningful Names
  • Introduction
  • Use Intention-Revealing Names
  • Avoid Disinformation
  • Make Meaningful Distinctions
  • Use Pronounceable Names
  • Use Searchable Names
  • Avoid Encodings
  • Avoid Mental Mapping
  • Class Names
  • Method Names
  • Don't Be Cute
  • Pick One Word per Concept
  • Don't Pun
  • Use Solution Domain Names
  • Use Problem Domain Names
  • Add Meaningful Context
  • Don't Add Gratuitous Context
  • Final Words
  • Chapter 3. Functions
  • Small!
  • Do One Thing
  • One Level of Abstraction per Function
  • Switch Statements
  • Use Descriptive Names
  • Function Arguments
  • Have No Side Effects
  • Command Query Separation
  • Prefer Exceptions to Returning Error Codes
  • Don't Repeat Yourself
  • Structured Programming
  • How Do You Write Functions Like This?
  • Conclusion
  • SetupTeardownIncluder
  • Bibliography
  • Chapter 4. Comments
  • Comments Do Not Make Up for Bad Code
  • Explain Yourself in Code
  • Good Comments
  • Bad Comments
  • Bibliography
  • Chapter 5. Formatting
  • The Purpose of Formatting
  • Vertical Formatting
  • Horizontal Formatting
  • Team Rules
  • Uncle Bob's Formatting Rules
  • Chapter 6. Objects and Data Structures
  • Data Abstraction
  • Data/Object Anti-Symmetry
  • The Law of Demeter
  • Data Transfer Objects
  • Conclusion
  • Bibliography
  • Chapter 7. Error Handling
  • Use Exceptions Rather Than Return Codes
  • Write Your Try-Catch-Finally Statement First
  • Use Unchecked Exceptions
  • Provide Context with Exceptions
  • Define Exception Classes in Terms of a Caller's Needs
  • Define the Normal Flow
  • Don't Return Null
  • Don't Pass Null
  • Conclusion
  • Bibliography
  • Chapter 8. Boundaries
  • Using Third-Party Code
  • Exploring and Learning Boundaries
  • Learning log4j
  • Learning Tests Are Better Than Free
  • Using Code That Does Not Yet Exist
  • Clean Boundaries
  • Bibliography
  • Chapter 9. Unit Tests
  • The Three Laws of TDD
  • Keeping Tests Clean
  • Clean Tests
  • One Assert per Test
  • F.I.R.S.T
  • Conclusion
  • Bibliography
  • Chapter 10. Classes
  • Class Organization
  • Classes Should Be Small!
  • Organizing for Change
  • Bibliography
  • Chapter 11. Systems
  • How Would You Build a City?
  • Separate Constructing a System from Using It
  • Scaling Up
  • Java Proxies
  • Pure Java AOP Frameworks
  • AspectJ Aspects
  • Test Drive the System Architecture
  • Optimize Decision Making
  • Use Standards Wisely, When They Add Demonstrable Value
  • Systems Need Domain-Specific Languages
  • Conclusion
  • Bibliography
  • Chapter 12. Emergence
  • Getting Clean via Emergent Design
  • Simple Design Rule 1: Runs All the Tests
  • Simple Design Rules 2-4: Refactoring
  • No Duplication
  • Expressive
  • Minimal Classes and Methods
  • Conclusion
  • Bibliography
  • Chapter 13. Concurrency
  • Why Concurrency?
  • Challenges
  • Concurrency Defense Principles
  • Know Your Library
  • Know Your Execution Models
  • Beware Dependencies Between Synchronized Methods
  • Keep Synchronized Sections Small
  • Writing Correct Shut-Down Code Is Hard
  • Testing Threaded Code
  • Conclusion
  • Bibliography
  • Chapter 14. Successive Refinement

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 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, 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 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 desribes 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 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. Excerpted from Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin All rights reserved by the original copyright owners. Excerpts are provided for display purposes only and may not be reproduced, reprinted or distributed without the written permission of the publisher.