back

by guytv·3y ago·view on hn ↗
I am using rule of two. I refactor at the second appearance. I started doing this when programming Ruby on Rails a few years back, where DRY (Don't repeat yourself) was a big thing there.
2 comments
I am using rule of 1.5. It's just like rule of 2, but I also name (e.g. make a separate function) any block of code whose result value is not obvious from a single glance.
That's a mistake that leads to premature generalization
It's a mistake to pick any of those rules as an absolute truth. It varies by task, maintenance and time constraints. DRY makes a lot of sense in some cases, but some others even need a rule of four+ (think of heuristics-heavy code). IMO DRY is most useful when working on a codebase owned by someone else than you.