Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Re-using showering code is less error prone than maintaining separate copies of showering code!


Not necessarily. When you make a single change to a shared function, you might cause undesired changes to other code that calls that function.


So 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.


No, 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.


It 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.


The function may be doing too much, then. It would probably contains several reusable pieces if you broke it up differently.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: