in

ASP.NET Weblogs

This Blog

Syndication

My Job

Jeff Key

It works on my machine

Code reuse: Does anyone still do this?

It startles me whenever I see add-ins, IDEs or people touting code libraries and code reuse.  Is anyone still copying and pasting code?  I have a couple standard comment headers and whatnot that I store in the VS.NET toolbar for reuse, but no code.  With all of the template-based code generators available now, I can't imagine why anyone would do this.  If something is reusable, wrap it up in a class and throw it in an assembly. 

On a related note, I get the heebie-jeebies when people mention pulling code from old apps to reuse in a new app, even if it was their own code.  The great thing about being in this profession is that you learn every day.  Any time anyone mentions pulling old code, I suggest pulling the ideas and leave the code where it is.  The hard part isn't writing the code, it's the concept behind it.  Take what you've learned and write something new and wonderful.

Conceptual reuse, that's where it's at.

Published Jul 13 2003, 03:27 PM by jeffreykey
Filed under:

Comments

 

Baby? Bathwater? said:

Of course by reusing only the concept and not the code, you're going to throw out all the little extras that the old codebase had to deal with along the way... gotchas, unknown requirements, bug fixes, etc, etc...
July 13, 2003 6:23 PM
 

Jeff Key said:

Good point; however, I've found that the time it takes for someone to sculpt the code into its new context could've been used to write it from scratch. Naturally, this depends on the amount of code. Bug fixes, requirements and the like from the old code may or may not pertain to the code's new home. I've seen this happen too many times. People patch together code from different projects and spend weeks trying to get it to work together because there are so many implementation-specific bits floating around. Of course, YMMV.
July 13, 2003 6:32 PM
 

Tim Marman said:

You'd be surprised how often people don't reuse code the way it should be done (ie a class library) and instead copy and paste.

It may save you some up-front development costs, but it sure as hell doesn't help maintenance costs and maintainability in general. In fact, it might even be worse if you have to keep the copy-and-pasted code in sync across different applications.
July 13, 2003 8:51 PM
 

Jason said:

Nice theory, but I work in the real world. Writing from scratch would be wonderful, but I have clients that pay me to deliver solutions, not continually improve with each and every line of code I right. We make the effort when we can, of course, but sometimes compromises have to be made.

As for general purpose assemblies, my experience is that it's sometimes much more efficient to just copy and paste instead of building "flea market" assemblies containing a raft of often unrelated routines. Again, there are exceptions and when you've got a large number of related routines it of course makes sense to package them up, but code reuse through libraries still has a place as well (esp. when you're talking about javascript or D/HTML snippets). Additionally, I'd suggest you consider that often routines need to be tweaked to fit the situation, and often it's more economical (and easier to maintain) to go to your code library as a starting point instead of generalizing or extending (and regression testing) your assembly routine.
July 14, 2003 9:33 AM
 

Jason said:

"right" in my previous post should, of course, be "write". Dammit, it's early here and I destroyed the credibility of a reasonably decent pseudo-rant :(
July 14, 2003 9:35 AM
 

Aemca said:

Maybe you should read what Joel has to say about this sort of thing:

http://www.joelonsoftware.com
July 17, 2003 10:12 AM

Leave a Comment

(required)  
(optional)
(required)  
Add