by DDSDev · 5y ago · 0 comments
To add on to that, I think the key behind DRY is to not repeat a concept within your codebase, and not failing into the trap of avoiding similar but slightly different code blocks that aren't exactly logically equivalent by carving up your code into nonsense. The former leads to elegant abstraction, while the latter just leads to functions with signatures like my_function(data, BITFIELD, opt1=false, opt2=true, opt3=false, BITFIELD);
If two things are _supposed_ to behave similarly, then not having duplicate code makes perfect sense.
If two things just _happen_ to behave similarly (at first), it may be a hasty generalisation to immediately refactor them to use the same code.
Dry is about not repeating behavior. It's not about not repeating text.
- business logic
- something that your extracting as a library
If there is bug, will someone have to fix it in one place. Or, remember it’s in 7 places. If later I DRY.