Use the before-and-after examples to refactor messy variable and function names in your own Python project.
Learn the SOLID principles through concrete Python 3 code instead of abstract definitions.
Review your codebase against the guide's checklist to spot naming, duplication, and class-design issues before code review.
Study the function-design rules to reduce argument counts and eliminate conditional logic hidden inside function bodies.
This repository is a guide to writing Python code that is easier to read, maintain, and work with over time. It adapts the principles from the book "Clean Code" by Robert C. Martin into Python-specific examples. The original book focuses on general software craftsmanship, and this project translates those ideas into concrete Python 3 code. The guide is organized into four main topics. The variables section covers naming: use names that are meaningful and pronounceable, stay consistent with the same word for the same concept across a codebase, avoid single-letter names that require the reader to hold a mental map, and do not pad variable names with redundant type or class information that the context already makes obvious. The functions section argues that each function should do exactly one thing. Functions that do multiple things are harder to test and harder to change. The guide also recommends keeping the number of arguments small, using default argument values instead of conditional logic inside the function body, and naming things so a caller can understand the function's purpose without reading its code. The classes section introduces the five SOLID principles: Single Responsibility (a class should have one reason to change), Open/Closed (extend behavior without modifying existing code), Liskov Substitution (subclasses should work wherever their parent is expected), Interface Segregation (clients should not depend on methods they do not use), and Dependency Inversion (depend on abstractions rather than concrete implementations). A final section covers avoiding repeated code. Each idea appears once, in one place, so that a future change only needs to happen in one spot. Every concept in the guide is illustrated with side-by-side bad and good code examples, making it straightforward to see the difference in practice. The guide targets Python 3.8 and later. The full README is longer than what was shown.
← zedr on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.