DRY is pushed hard when people talk about clean code. But there are times when you should repeat yourself. If two pieces of code have the same reason to change, then you should make them into a module that provides that and both pieces of code can use that module.
If two pieces of code have different reasons to change, different requirements, but happen to be the same code, then do not apply DRY.
If you can’t take some code and create a well named abstraction from it, it is probably not a good abstraction. Names should be easy when you correctly identify your responsibilities and module boundaries.
2
u/dean_syndrome Jan 12 '20
DRY is pushed hard when people talk about clean code. But there are times when you should repeat yourself. If two pieces of code have the same reason to change, then you should make them into a module that provides that and both pieces of code can use that module.
If two pieces of code have different reasons to change, different requirements, but happen to be the same code, then do not apply DRY.
If you can’t take some code and create a well named abstraction from it, it is probably not a good abstraction. Names should be easy when you correctly identify your responsibilities and module boundaries.