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

I've tended to approach refactoring common functionality based on whether two pieces of code are either "coincidentally" the same or "intrinsically" the same.

If code is coincidentally the same, then you should leave it alone - the two pieces of code are likely to evolve independently and trying to make a common function/class handle two separate usecases is likely to lead to complex, ugly code.

Conversely, if the two pieces of code are intrinsically the same then you SHOULD pull them out into something common. If you don't, you risk the implementations drifting and getting inconsistent behaviour over time.

Determining which is which is a matter of interrogating your domain and business logic, which is the essential function of our job as developers/engineers.



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

Search: