3 ms·
I think the only hard and fast rule is to DRY the code that will introduce a bug if you change it in one place and not the other. And if it will, at least do a
by renegade-otter 2y ago
I think the only hard and fast rule is to DRY the code that will introduce a bug if you change it in one place and not the other. And if it will, at least do a fat comment in both places for posterity.
Whenever I have to have a "mental model" of the code, I know I screwed up.
- senkora 2y ago+1. If I go with the comment option, then I'll sometimes write a comment like "If you change this here, then you must change it everywhere with this tag: UNIQUE-TAG". This way, the reader can just do a global grep to find all the places to change, and you don't have to list them in each place and keep them in sync.
- randomdata 2y agoA comment is a nice addition, but the very least is to ensure that your test suite properly covers cases where changing one and not the other will introduce a problem. This not only ensures that both are changed, but that both are changed in the way they need to be. A comment alone may prompt you to change both (if you ever read it - I bet a lot of developers don't), but you may not notice when you fail to change them in the same way, which is no better than not changing one.