explaingit

zedr/clean-code-python

4,799PythonAudience · developerComplexity · 1/5Setup · easy

TLDR

A practical guide to writing cleaner, more readable Python 3 code based on Robert C. Martin's Clean Code book, with side-by-side good and bad examples covering naming, functions, SOLID class design, and avoiding duplication.

Mindmap

mindmap
  root((clean-code-python))
    Variables
      Meaningful names
      Avoid abbreviations
      Consistent naming
    Functions
      Single purpose
      Few arguments
      Default values
    Classes
      Single Responsibility
      Open Closed
      Dependency Inversion
    Code quality
      No duplication
      Self-documenting
      Python 3 examples
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Use the before-and-after examples to refactor messy variable and function names in your own Python project.

USE CASE 2

Learn the SOLID principles through concrete Python 3 code instead of abstract definitions.

USE CASE 3

Review your codebase against the guide's checklist to spot naming, duplication, and class-design issues before code review.

USE CASE 4

Study the function-design rules to reduce argument counts and eliminate conditional logic hidden inside function bodies.

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

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.

Copy-paste prompts

Prompt 1
Using the naming rules from zedr/clean-code-python, review this Python function and rename all variables to be meaningful and self-documenting without abbreviations.
Prompt 2
Apply the Single Responsibility Principle from clean-code-python to this Python class and split it into focused, single-purpose classes.
Prompt 3
My Python function takes 6 parameters. Using the clean-code-python function guidelines, refactor it to reduce the argument count without changing its behavior.
Prompt 4
Review this Python module for Clean Code violations, naming, duplication, and class design, and list each issue with a specific fix recommendation.
Prompt 5
Using the clean-code-python guide's DRY principle, find every place this codebase repeats the same logic and refactor it into a single reusable function.
Open on GitHub → Explain another repo

← zedr on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.