Skip to content
I'll Be Back
end
Lessons
How it works
Search lessons
/
@illbebackend
Lessons
/
Principles
/
DRY: one rule, one place
Principles · Python
DRY: one rule, one place
Change a business rule once and have every feature pick it up.
12 steps
4 chapters
~3 min at 1.25×
#duplication
#constants
#single source of truth
Language
Java
Kotlin
C#
C++
Python
Ruby
PHP
TypeScript
JavaScript
Go
Rust
Swift
The lesson plays right here. Pause anywhere, step back, or jump to a step below.
Watch the Python video on YouTube
Code on GitHub
Every step
Problem
Steps 1–3
01
Three features, one rule
Before
02
Members ship free from 25
Code smell
03
Undo, then give it a home
Plan
Refactor
Steps 4–9
04
Name the limit
Replace Magic Number with Constant
05
Name the fee
Replace Magic Number with Constant
06
Name the check
Extract Function
07
The banner asks too
Replace Inline Code with Function Call
08
The email asks too
Replace Inline Code with Function Call
09
Name the gap
Extract Function
Payoff
Step 10
10
Members, in one helper
Payoff
Recap
Steps 11–12
11
Where we started, where we ended
Before / after
12
When to reach for it
Takeaways