A performance comparison project demonstrating different coding approaches in Python: clean code patterns vs unreadable implementations.
- Python 3.13 or higher
- uv package manager
If you don't have uv installed, you can install it using one of the following methods:
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | shWindows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"Using pip:
pip install uv- Clone the repository (if you haven't already):
git clone https://github.com/giuliowaitforitdavide/python-clean-code-debate.git
cd python-clean-code-debate- Create a virtual environment and install dependencies:
uv syncThis command will:
- Create a virtual environment (if it doesn't exist)
- Install all project dependencies from
pyproject.toml - Install development dependencies (pytest, factory-boy, ruff)
- Lock dependencies in
uv.lock
- Activate the virtual environment:
macOS/Linux:
source .venv/bin/activateWindows:
.venv\Scripts\activateTo run all performance benchmarks:
pytestOr using the Makefile:
make complete-benchmarkThe project includes three specific performance tests comparing different approaches:
1. Polymorphism Benchmark
make poly-benchmarkor
pytest -q tests/test_performance.py::test_performance_polymorphism2. Internals Benchmark
make internals-benchmarkor
pytest -q tests/test_performance.py::test_performance_internals3. Simple Benchmark
make simple-benchmarkor
pytest -q tests/test_performance.py::test_performance_simpleFor more detailed test output, remove the -q flag:
pytest tests/test_performance.py -vpython-clean-code-debate/
├── src/ # Source code
│ ├── __init__.py
│ ├── models.py # Shape models (Circle, Rectangle, Square, Triangle)
│ ├── clean_code.py # Clean code implementation
│ ├── polymorphism.py # S.O.L.I.D. unreadable implementation
│ ├── internals.py # T.D.A. unreadable implementation
│ └── simple.py # K.I.S.S. unreadable implementation
├── factories/ # Test data factories
│ ├── __init__.py
│ └── shape_factories.py # Factory Boy factories for shapes
├── tests/ # Test suite
│ ├── __init__.py
│ ├── conftest.py # Pytest fixtures
│ └── test_performance.py # Performance tests
├── Makefile # Build and test automation
├── pyproject.toml # Project configuration
├── uv.lock # Locked dependencies
└── README.md # This file
This project uses Ruff for linting and formatting:
Check for issues:
ruff check .Auto-fix issues:
ruff check --fix .Format code:
ruff format .Add a runtime dependency:
uv add <package-name>Add a development dependency:
uv add --dev <package-name>This project compares the performance of different coding approaches:
- Clean Code Approach: Follows clean code principles with emphasis on readability
- Polymorphism Unreadable Implementation: Show how using S.O.L.I.D. principles affect performance
- Internals Unreadable Implementation: Show how using T.D.A. principles affect performance
- Simple Unreadable Implementation: Show how using K.I.S.S. principles affect performance
Each test measures execution time to demonstrate the performance trade-offs between clean, readable code and unreadable implementations.
See LICENSE file for details.