Of course in the "Industry" , I wouldn't say Copy Pasting is bad as the clients want |
I see copy and pasting as very bad.
(Edit: not sure I'm thinking of copy and paste in quite the same sense?)
There are times when it's expedient to copy and paste a little bit, to hit a deadline. But under normal circumstances, any significant bit of code should be factored out into a common library and then used in all the places it's needed. While this takes a little bit more time in the short term, it pays off in the mid to long term.
(Copying small bits of functions doesn't count, esp. if their routine. I assume, of course, that no bit of code is copied if it is not fully understood.)
Of course, copy and pasting does go on. But when you've been tasked to propagate a fix to all copies of a defective paste a few times, you learn not to do it.
Andy
PS The reason limited copy and paste would be acceptable near a deadline is that it could require less rebuilding. Any full rebuild would, of course, require full retesting.
For example, you have a function which is already being used in only one DLL/shared object but at the last moment, you find you need the same code to fix a problem in another module. Ideally you would factor the code out into the appropriate shared library and rebuild everything. But if you've already unit tested everything, you only really want to rebuild and unit test the module you fixed. So you copy and paste the required bit of code.
But what you also do, as soon as you ship, is repair the library before moving on to work on the next release of the application (if there is going to be one).
Note that I where I've worked, the unit in unit test usually mean an API (i.e. the external calls of a module). Though we do also use some lower level unit tests which work against a class or function, or group of them.