DRY
easy 40 minDon't repeat yourself: every piece of knowledge has one home, and everything else asks that home.
Watch lesson4:18
Remember it
The few things worth knowing cold, and how to make them stick.
Memory hook
One fact, one home, many readers.
Five painted doors need five brushes. One board at the gate and five arrows need one. But the bus has its own board, even if it says 8 - 4 today.
Cheat sheet
- DRY
- one home for each piece of knowledge
- WET
- write everything twice
- Test
- how many places do I edit by hand?
- Merge if
- one reason changes both
- Rule of three
- extract at the third copy
- Way back
- inline, trim, extract again
- Library
- one source, many live versions
- Derived copy
- who is in charge, how old, how checked
Spot it when you see
- The same commit touches several files in the same way
- A number without a name
- A bug that comes back in another screen
- A comment: keep in sync with ...
- Copy and paste in the last hour
Tricks that stick
- D, R, Y: Don't (avoid) Repeat (duplicate) Yourself (code and data).
- A desert is dry: no extra water, no extra copies. But even a desert has a few wells where they are needed.
- Say the name of the extracted thing. If you need the word and, stop.
Do not forget
- Merging equal text with different owners
- Helpers with flags that name callers
- Shared domain classes across services
- Constant shared, formula still copied
- Editing generated files