4 ms·
Not necessarily. When you make a single change to a shared function, you might cause undesired changes to other code that calls that function.
by pdubroy 18y ago
Not necessarily. When you make a single change to a shared function, you might cause undesired changes to other code that calls that function.
- xenophanes 18y agoSo you're advocating copy/paste style coding, and telling us it is less buggy? Seriously? And without some extensive explanation? What about the studies showing number of bugs is proportional to lines of code? Your way adds more lines of code.
- pdubroy 18y agoNo, I'm saying that putting common code in a separate method is not necessarily -- as in, "as a logical result or consequence" -- less error-prone. I'm not advocating cutting and pasting huge blocks of code everywhere, but a 1-line calculation duplicated in 4 spots is probably okay.
- deleted 18y ago[deleted]
- smhinsey 18y agoIt probably is okay to duplicate a calculation 4 times, all other things being equal. At the same time, I'd say it's probably a sign of other problems. If you need to reuse a calculation, that calculation is part of your application's domain (using the term loosely) and should be represented there, rather than being embedded inside scenario-appropriate parts of the system.
- silentbicycle 18y agoThe function may be doing too much, then. It would probably contains several reusable pieces if you broke it up differently.