Share E-Book
Scan to open this page

Scan with your phone to open this page

AuthorRobert C. Martin

This new edition of the classic guide to software craftsmanship --a comprehensive rewrite of the original bestseller--is poised to transform the way developers approach coding, fostering a deeper commitment to the craft of writing clean, flexible, and maintainable code. Offering a deeper exploration of testing, design, and architecture, alongside universal coding principles applicable across various programming languages, this edition is set to be an indispensable resource for developers, engineers, and project managers. Divided into four parts--basic coding practices, design principles and heuristics, high-level architecture, and ethics of craftsmanship--this book challenges readers to critically evaluate code quality and reassess their professional values, ultimately guiding them to produce better software. This edition includes expanded coverage of testing disciplines, design and architecture principles, and multiple programming languages.

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
# Clean Code: A Handbook of Agile Software Craftsmanship, 2nd Edition ## 【One-Line Pitch】 A masterclass in writing readable, maintainable, and professional software—essential reading for developers, engineers, and technical leads who want to elevate their craft and take responsibility for the quality of their code. This second edition expands on the original with deeper coverage of testing, design principles, architecture, and the ethics of software craftsmanship. ## 【Book Arc】 - **Opening (~0%–10%)**: Establishes the moral and professional stakes of software quality, citing real-world disasters caused by poor code. Introduces the core premise: writing clean code is a professional obligation, not just a stylistic preference. - **Early (~10%–23%)**: Dives into fundamental coding practices—naming conventions, functions, comments, and formatting. Uses concrete examples (like the Roman numeral converter and rental system) to demonstrate how small, disciplined choices compound into readable code. - **Middle (~23%–48%)**: Moves into design principles and heuristics—encapsulation, extraction, dependency management, and the trade-offs of code organization. Includes multi-language examples (Go, Python, Ruby, Java) showing how the same principles apply across paradigms. - **Late (~48%–70%)**: Explores high-level architecture—module organization, class design, and system-level thinking. Discusses how to structure code for growth and change without sacrificing clarity. - **Ending (~70%–100%)**: Concludes with the ethics of craftsmanship—the professional responsibilities of a software developer, including testing discipline, continuous improvement, and the "sushi chef" mentality of never letting the mess grow too big. ## 【Key Takeaways】 - **Naming is the first line of defense** (Early): Intention-revealing names answer why, what, and how—eliminating the need for explanatory comments. A name like `elapsedDays` beats `d` because it encodes both meaning and unit. - **Functions should do one thing, well** (Early): Extract until you drop—small functions with clear responsibilities are easier to test, debug, and reuse. Modern compilers inline single-call functions automatically, so there's no performance penalty. - **Comments are a last resort, not a crutch** (Early): Good comments explain "why," not "what." Commented-out code is an abomination—delete it. If a name requires a comment to be understood, the name is wrong. - **Encapsulation supports extraction** (Middle): Breaking encapsulation is sometimes necessary to enable clean extraction of methods. The goal is to keep coupling low and cohesion high, even if it means exposing internals temporarily. - **Output arguments violate the principle of least surprise** (Early): Data should flow into functions through arguments and out through return values. Multiple return values (as in Go, Python, Ruby) are preferable to output parameters. - **Organize code in call order** (Middle): Arrange extracted functions in the order they're called—A, B, C—so readers can scroll down through the code from high-level to low-level without bouncing around. - **One module per file, with rare exceptions** (Late): Even when languages allow multiple classes per file, stick to one primary type per source file. Small, closely-related structs or exception types are acceptable exceptions. - **Clean code requires a continuous cleaning loop** (Middle): Write, clean one small thing, run tests, revert if broken, repeat. Never let the mess accumulate beyond what you can clean in one sitting. ## 【Reading Tips】 - **Skim the opening chapters** (~0%–10%) if you're already convinced about the importance of code quality—the real value starts with the naming and function chapters. - **Deep-read the naming and function chapters** (~10%–23%): These are the most actionable and immediately applicable. Work through the examples with your own code. - **Pay attention to the multi-language examples** (Middle): Even if you don't use Go, Python, or Ruby, the patterns translate. The Go video store refactoring is particularly instructive. - **Don't skip the "bad code" examples**: The book deliberately shows poor code first so you can feel the pain before seeing the solution. Resist the urge to jump ahead. - **Take away the cleaning loop, not just the rules**: The most important habit is the continuous cycle of small improvements with test verification—adopt this as a daily practice. ## 【Coverage Limits】 The excerpts cover the opening through roughly the middle of the book (up to ~48%), focusing on basic coding practices and early design principles. The later sections on high-level architecture and the ethics of craftsmanship are described in the blurb but not detailed in the available material. ##
Excerpt 1
oftware errors kill dozens, and injure hundreds, when their cars’ computers lost their minds and accelerated out of control. We saw Knight Capital lose $450M...
View in text
Excerpt 2
problem domain. We don’t force solution domain names on the problem, nor problem domain names on the solutions. Add Meaningful Context There are a few names...
View in text
Excerpt 3
nder what’s going on. That’s because they expect data to go into functions through the arguments and out from functions through the return value. In Go, Pyth...
View in text
Excerpt 4
, but now you’ve forgotten why you were worried about that. You click back to where you were, and you’ve lost your train of thought and have to backtrack sev...
View in text
Excerpt 5
new-words)] (str/join " " trimmed-words))) (defn sentence-walk [filename initial-substring] "Main function to perform the sentence walking process." (let [se...
View in text
Excerpt 6
nters, View, Controllers, and then Authorizer. Main is last. This process is very clear and easy to deal with. We know how to build the system because we und...
View in text
Excerpt 7
with about fifty programmers, and perhaps three were women. So, 30 years after Turing, the demographics of programming had shifted dramatically toward very y...
View in text
Excerpt 8
lowing one of the testing disciplines gives us a good start on a semantically stable test suite; but none of those disciplines is sufficient for full semanti...
View in text
Tags
AI categories
Programming LanguageCodeProgramming
ISBN: 0135398576
Publish Year: 2025
Language: English
File Format: PDF
File Size: 19.4 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…