recently I have released a software called Clone Detective for Visual Studio (CodePlex). This tool allows you to find duplicated source code in C# projects. Although this is a very powerful tool it does not prevent copy & paste coding before it happens; it can only detect it.
What do you do against this well known behavior? Code reviews? Better dev education? Aspect oriented programming (e.g.with PostSharp)?
I believe code duplication is not always something one must fight. For example, our company sometimes intentionally duplicates source code in order to remove a dependency between two components. I think from time to time it is better to eliminate a dependency instead of taking code reuse to the extreme. More dependencies make a system more complex and harder to support. On the other hand I have heard the Excel team at Microsoft has made a religion out of this -- they even have developed their own C compiler. I believe this takes dependency elimination a bit too far. (to be honest, this story about the Excel could also be an urban legend )
What do you think? How do you fight copy & paste? Do you fight at all?
The best written code is none at all. If the shared code is well documented and the API is clean, there is much less incentive to roll your own solution to a problem that has been solved already. Avoid creating large classes that do all kinds of things, keep them small, single purposed and use names that clearly define what it is your class does. These simple rules encourage code reuse.
darwin's survival of the fitest.
"Good" developers do not want to just copy mindlesly.
"Good" developers learn, grow, advance...
hacks who try to just copy will fall out.