Clean Code
Write readable, maintainable code that other developers will love.
47 lessons
Class Organization
Classes should be small, focused, and have a single reason to change.
The Clean Code Mindset
Why clean code is a professional discipline — and how dirty code silently destroys teams and companies.
Clean Concurrency Strategies
Write concurrent code that is correct, readable, and free of subtle data-race bugs.
Clean Error Handling
Error handling is a separate concern — keep it isolated so your main algorithm stays readable.
Clean Unit Testing
Tests are first-class code — dirty tests become as costly to maintain as production code.
Comment Heuristics
Identify and eliminate bad comments; write the rare good one with precision.
Concurrency: Client-Server Model
Structure client-server concurrent systems to isolate shared state and avoid subtle threading bugs.
Concurrency: Deadlock & Starvation
Recognize and eliminate the four conditions that produce deadlock in concurrent systems.
Deadlock: The 4 Conditions
A deadlock requires all four Coffman conditions simultaneously — break any one and deadlock becomes impossible.
Concurrency: Jiggle Testing
Race conditions hide in timing gaps — shaking execution order with random yields and multi-platform runs forces them into the open.
Don't Repeat Yourself
🔒Every piece of knowledge must have a single, authoritative representation in the codebase.
Duplication & Abstraction
🔒Recognize hidden duplication and choose the right abstraction to eliminate it.
The 5S Philosophy in Code
🔒How the Toyota 5S manufacturing philosophy maps to professional software craftsmanship — naming, organization, cleaning, standardization, and discipline.
Framework Analysis
🔒Understand what a framework does before using it — read the source, not just the docs.
Function Heuristics
🔒Apply the F1–F4 heuristics to keep functions minimal, focused, and side-effect-free.
Abstraction Levels & Dependencies
🔒Keep high-level policy separate from low-level detail, and ensure base classes never depend on derived classes.
Coherence & Clarity
🔒Apply the same pattern everywhere, avoid conceptual clutter, and never couple unrelated concerns.
Conventions & Magic Numbers
🔒Follow team coding standards religiously and replace every magic literal with a named constant.
Environment & Truth
🔒Build systems that compile in one step, run all tests in one step, and never lie through suppressed warnings.
Expressiveness & Algorithms
🔒Use explanatory variables, precise names, and a deep understanding of the algorithm to make code speak for itself.
Feature Envy
🔒A method that spends most of its time reading another class's data belongs in that class.
Logic & Polymorphism
🔒Make all dependencies explicit, and replace if/switch chains with polymorphic dispatch.
Noise & Organization
🔒Eliminate excessive information, dead code, and vertical distance to keep every file easy to scan.
Placement & Statics
🔒Put every function in the class most interested in it, and keep static methods truly stateless utilities.
Selectors & Intent
🔒Boolean and enum selector arguments obscure intent — split them into focused, well-named functions.
Heuristics Catalog Overview
🔒A curated catalog of code smells and refactoring heuristics drawn from Clean Code chapter 17.
G16: The Obscured Intent
🔒Code that tries to be clever is code that fails to communicate — density and brevity at the cost of clarity are not virtues.
G21: Understanding the Algorithm
🔒Tests passing is not the same as understanding — clean code requires you to fully grasp why the algorithm works before you commit it.
G22: Logical to Physical Dependencies
🔒Never let a module silently assume a value from another — make every dependency explicit and declared in code.
Java-Specific Heuristics (J1–J3)
🔒Three Java-focused heuristics: avoid wildcard imports, never inherit constants, and prefer enums over integer constants.
Legacy Code Refactoring
🔒Safely transform tangled legacy code by adding tests first and refactoring in small steps.
The Art of Naming
🔒Write names that reveal intent, avoid confusion, and make code searchable.
Naming Heuristics
🔒Apply the N1–N7 heuristics to write names that are accurate, unambiguous, and searchable.
The Necessary Evil of Comments
🔒Code is the only source of truth — comments lie as the code evolves.
Objects vs Data Structures
🔒Objects hide data behind behavior. Structures expose data. Mixing both creates hybrids nobody wants.
Programmer Ethics & Attitude
🔒Quality is a professional responsibility — not something you deliver when time allows, but the non-negotiable minimum of your craft.
Pure Functions
🔒A pure function always returns the same output for the same input and changes nothing outside itself.
Responsibility Selectors
🔒Use the Single Responsibility heuristics to detect and split overloaded classes and modules.
SerialDate: Cleanup & Transformation
🔒Apply successive refinement to the SerialDate class — test, rename, extract, and simplify.
SerialDate: Diagnosis
🔒A case study in reading legacy code critically — find the smells before touching anything.
The 4 Rules of Simple Design
🔒Kent Beck's four rules, in priority order, for a design that is always ready to evolve.
Small Functions
🔒Functions should do one thing, do it well, and do it only.
Style & Format as Communication
🔒Code formatting is a communication act — structure files so any developer can navigate them in seconds.
Successive Refinement
🔒Start with working code, then refactor iteratively — never write clean code in one pass.
System Boundaries
🔒Third-party code belongs at the edge — wrap it so it never pollutes your business logic.
The Three Laws of TDD
🔒Master the red-green-refactor micro-cycle: write a failing test first, then only the code needed to pass it.
Testing Heuristics
🔒Apply the T1–T9 heuristics to write complete, meaningful, and maintainable test suites.