Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Another alternative to DRY is WET: Write Everything Twice. Only make an abstraction on the third code repetition.

I started adopting this a few years ago and it’s surprising how seldom I hit three identical, non-trivial code repeats. Saved a lot of hours over the years not making a seemingly prudent generic layer.



I've found the whole "once is happenstance, twice is coincidence, thrice is a pattern" bit to be far more useful over time than DRY.


Nothing is more frustrating than having a colleague who never gets things done and are constantly writing abstractions for days. Like bro, you ain't gonna need this - I know you're flexing your abstract methods but it is fucking useless if it will never have more than one overrides.


I don’t understand this argument. It’s trivial to de-duplicate an abstraction by just inlining the code. How is that less efficient than duplicating code? At least in the meantime you get the benefit of shared code changes.


This is a good rule of thumb to adopt in teams and point out in code reviews.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: