Hacker News new | past | comments | ask | show | jobs | submit login

So, this take is sort of fashionable now, but it’s never really convinced me: what I’d suggest is that, when you discover that the extracted method is a bad abstraction, you do one of two things: (1) inline the method (IntelliJ is great at this for Java) or (2) duplicate the method and rename, adjusting the new version for the new use case. As hard as naming may be, adding the level of abstraction often ends up helping keep each method working at a single level of abstraction.

In my experience, the biggest messes I’ve inherited were a result of not being DRY enough: the cases of incidental duplication I’ve run across have been comparatively easy to unwind.




Couldn’t agree more. I can agree that premature abstraction is bad. But unnecessarily duplicated code outweighs this by orders of magnitude, in my experience. So stay DRY, and later when you hit that 1 case in 100 where the code needs to diverge, it’s easy enough to copy/paste.


This is a very key point - when you re-use, you often need to rename. I actually can't think of a clear example, but this happens ALL the time.




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

Search: