🧩Don't Repeat Yourself (DRY)
Also known as DRY, DRY Principle, Don't Repeat Yourself
The rule that each piece of logic should live in one place in your code.
Think of it like
Think of it like one shopping list on the fridge. Three copies would soon stop matching.
Example
Jack's shop works out tax in four places. When the rate changes, he updates three and forgets one. After moving it into one function, a change is one line.
Why it matters
Copied logic drifts apart. Keeping one copy means one fix, and no copy left behind with the old bug.
Definition
Common mistake
Key takeaways
- 1One place. For each piece of logic.
- 2One fix. Not five.
- 3Same meaning, not same look. Look-alikes may stay apart.