Track 04 · Lesson 15 of 15Code that stays easy to change
- 01Principles at a glance
- 02SOLID principles at a glance
- 03S: Single responsibility
- 04O: Open/closed
- 05L: Liskov substitution
- 06I: Interface segregation
- 07D: Dependency inversion
- 08Separation of concerns
- 09DRY: Don't repeat yourself
- 10KISS: Keep it simple
- 11YAGNI: You aren't gonna need it
- 12Composition over configuration
- 13Fail fast
- 14Least surprise
- 15When they disagree
Track 04 · Code that stays easy to change
When they disagree
Lesson 15 of 15· 5 min
These principles pull against each other. That's expected: they're questions to ask, not laws to obey. Here are the three tensions you'll meet most often. Pick a side in each, then see what experienced engineers usually do.
Three real dilemmas
Pick a side in each
DRY versus simple
Two components each have a six-line helper that formats dates. One formats invoice dates the way your accountant requires; the other shows “3 days ago” in the UI. They look almost identical.
Single responsibility versus YAGNI
A 40-line settings component works and is easy to read. A reviewer asks you to split it into five files “for single responsibility”. Nothing about it is changing for a second reason yet.
Fail fast versus a calm interface
The prices API starts returning malformed data in production. Your boundary check catches it. What should the customer see?
DRY versus simple#
Removing duplication adds an abstraction. If the abstraction is harder to follow than the copies, keep the copies. Many teams wait for the third repeat, when the shared rule is clear.
Single responsibility versus YAGNI#
Splitting a 40-line component into five files "for responsibility" is its own kind of speculation. Split when a second reason to change actually shows up.
Fail fast versus a calm interface#
Be loud at the boundary, in development and in your logs. In front of a user, catch the error and offer a way forward. Loud for developers, calm for users.
The tiebreaker#
When principles disagree, ask which version a teammate could read, change and trust most easily, six months from now, without you in the room. That's usually the answer.
Check yourself