Subj : Re: Polymorphism sucks [Was: Paradigms which way to go?] To : comp.programming,comp.object From : topmind Date : Tue Jun 28 2005 06:20 pm > > > Copy-and-paste actually *reduces* coupling because it lets things be > > independent, for example. Thus, if reducing coupling is always good, > > then copy-and-paste is always good. > > It may appear to reduce coupling, but as has been said, it creates an > invisible (to the source) web of coupling that needs to be documented > and maintained by the developer. Yes, but that is a nebulous form of "coupling". Robert Martin implied that "coupling" was sure-shot metric that by itself would guide decisions. But if the coupling is only in the mind rather than in code, then it loses that status. > > That is, unless, the copied parts have absolutely no need to be in sync > with the the originals. We don't know for sure either way up-front. They may need syncing in the future or they may not. It is a matter of *probability*, something that Robert failed to adaquately address. This is why such "mental coupling" tells us almost nothing about such a decision. > For example, if I copy'n'paste a routine from > a totally separate program as a form of code reuse, that's fine. > > But creating identical bits of source that are actually logically coupled > is a horrible bad idea. One of the biggest problems developers wrestle > with is the "synchronization problem", and it occurs any time you have > two (or more) things that need to be kept in sync. A simple example is > source and comments. They need to be kept in sync, or you end up with > comments that are lies or half-truths. > > It is far better practice to factor out common functionality. Ideally, > you never want duplicate code, ever! > Note that I was not promoting copy-and-paste above. I was only exploring it's relationship to Robert's view of "coupling". -T- .