4 ms·
One rule that I think works well: If DRYing the function would entail adding a conditional statement, don't. Even if remaining 90% stays the same. That 90% is
by ilyt 4y ago
One rule that I think works well:
If DRYing the function would entail adding a conditional statement, don't. Even if remaining 90% stays the same. That 90% is a good candidate to dedupe tho.
- dimal 4y agoExactly. Reuse through conditionals is a trap. “Look! I made a reusable thing!” No, you made a choke point. Dedupe what you can, then compose with the other 10% when you need it. No need to complect it, as Rich Hickey would describe it.
- steve_adams_86 4y agoI think composition is often the tool that’s needed when trying to hit two birds with one stone, but not reached for as often as it should be. Although conditional statements are totally useful and essential, I find their overuse tends to look like the logic is especially departed from the data structures it operates on. On the other hand, composition tends to accomplish the opposite — it reads with clearer intent and reveals more about what’s similar or dissimilar in various parts of your data. It’s totally possible to compose poorly too, of course. Plenty of ways to write awful code :)
- JadeNB 4y ago> If DRYing the function would entail adding a conditional statement, don't. Even if remaining 90% stays the same. That 90% is a good candidate to dedupe tho. Carmack mentions this rule in slightly different terms (https://twitter.com/ID_AA_Carmack/status/1646638023499456517 https://twitter.com/ID_AA_Carmack/status/1646638023499456517): > It is often still a good trade if an abstraction may induce some extra work where not strictly necessary, but a bad trade when you start introducing conditional behavior in your abstraction.