views:

777

answers:

17

A couple of years ago the media was rife with all sorts of articles on how the idea of code reuse was a simple way to improve productivity and code quality.

From the blogs and sites I check on a regular basis it seems as though the idea of "code reuse" has gone out of fashion. Perhaps the 'code reuse' advocates have all joined the SOA crowd instead? :-)

Interestingly enough, when you search for 'code reuse' in Google the second result is titled:

"Internal Code Reuse Considered Dangerous"!

To me the idea of code reuse is just common sense, after all look at the success of the apache commons project!

What I want to know is:

  • Do you or your company try and reuse code?
  • If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?
  • Does it work?

Discuss?

+1  A: 

We reuse code.

On a small scale we try to avoid code duplication as much as posible. And we have a complete library with a lot of frequently used code.

Normally code is developed for one application. And if it is generic enough, it is promoted to the library. This works excelent.

Gamecat
+2  A: 

I think code reuse is being done through open source projects for the most part. Anything that can be reused or extended is being done via libraries. Java has an amazing number of open source libraries available for doing a large number of things. Compare that to C++, and how early on everything would have to be implemented from scratch using MFC or the Win32 API.

Kieveli
A: 

If you decided that code is generic enough to shared across your org. What is the process you go through to get that code shared.

I am interested in how people go about facilitating code reuse? For example how to do you go about informing other members of your team that your code is there to be shared.

karl

Karl
This is not an answer. Use a comment, or edit your question.
Geoffrey Chetwood
+1  A: 

The idea of code reuse is no longer a novel idea...hence the apparent lack of interest. But it is still very much a good idea. The entire .NET framework and the Java API are good examples of code reuse in action.

We have grown accustomed to developing OO libraries of code for our projects and reusing them in other projects. Its a part of the natural life cycle of an idea. It is hotly debated for a while and then everyone accepts and there is no reason for further discussion.

Vincent Ramdhanie
A: 

Of course we reuse code.

There are a near infinite amount of packages, libraries and shared objects available for all languages, with whole communities of developers behing them supporting and updating.

adam
+8  A: 

The title of the article you are referring to is misleading, and is actually a very good read. Code reuse is very beneficial, but there are downsides with everything. Basically, if I remember correctly, the gist of the article is that you are sealing the code in a black box and not revisiting it, so as the original developers leave you lose the knowledge. While I see the point, I don't necessarily agree with it - at least not to a "sky is falling" regard.

We actually group code reuse into more than just reusable classes, we look at the entire enterprise. Things that are more like framework enhancement or address cross-cutting concerns are put into a development framework that all of our applications use (think things like pre- and post-validation, logging, etc.). We also have business logic that is applicable to more than one application, so those sort of things get moved to a BAL core that is accessible anywhere.

I think that the important thing is not to promote things for reuse if they are not going to really be reused. They should be well documented, so that new developers can have a resource to help them come up to speed, as well. Chances are, if the knowledge isn't shared, the code will eventually be reinvented somewhere else and will lead to duplication if you are not rigorous in documentation and knowledge sharing.

joseph.ferris
"The title of the article you are referring to..." I was not referring to anything in particular, did this ring a bell with something you have read before? Karl
Karl
The second result you saw in Google. "Internal Code Reuse Considered Dangerous". It is a whitepaper that I read a while back.
joseph.ferris
+1  A: 

I think the lack of "media attention" is due to the fact that everyone is doing it, so it's no longer worth writing about. I don't hear as many people raising awareness of Object-Oriented Programming and Unit Testing as I used to either. Everyone is already aware of these concepts (whether they use them or not).

Bill the Lizard
+3  A: 

Code reuse is essential. I find that it also forces me to generalize as much as possible, also making code more adaptable to varying situations. Ideally, almost every lower level library you write should be able to adapt to a new set of requirements for a different application.

hmcclungiii
".. every lower level library you write should be able to adapt to a new set of requirements for a different application" Say for example you write a low level JMS lib and you want to share it with the community, how would you go about sharing it? Its unlikely ill find it on your personal website.
Karl
There are many websites, applications and services available for this.
hmcclungiii
A: 

I am fully aware that there are many open source libs available and that anyone who has used .NET or the JAVA has reused code in some form. That is common sense!

I was referring more to code reuse within an organizations rather than across a community via a shared lib etc.

I originally asked;

  • Do you or your company try and reuse code?
  • If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?

From where I sit I see very few example of companies trying to reuse code internally?

If you have a piece of code which could potentially be shared across a medium size organization how would you go about informing other members of the company that this lib/api/etc existed and could be of benefit?

Karl
Again, this is not an answer, this is a comment. Make it a comment, or edit your question.
Geoffrey Chetwood
A: 

While I think code reuse is valuable, I can see where this sentiment is rooted. I've worked on a lot of projects where much extra care was taken to create re-usable code that was then never reused. Of course reuse is much preferable to duplicate code, but I have seen a lot of very extenisve object models created with the goal of using the objects across the enterprise in multiple projects (kind of the way the same service in SOA can be used in different apps) but have never seen the objects actually used more than once. Maybe I just haven't been part of organizations taking good advantage of the principle of reuse.

Jim Anderson
A: 

Maybe the better question is when do we NOT reuse code these days? We are either in a state on building using someone elses observed "best practices" or prediscovered "design patterns" or just actually building on legacy code, libraries, or copying.

It seems the degree to which code A is reused to make code B is often based around how much the ideas in code A taken to code B are abstracted into design patterns/idioms/books/fleeting thoughts/actual code/libraries. The hard part is in applying all those good ideas to your actual code.

Non-technical types get overzealous about the reuse thing. They don't understand why everything can't be copy-pasted. They don't understand why the greemelfarm needs a special adapter to communicate the same information that it used to to the old system to the new system, and that, unfortunately we can't change either due to a bazillion other reasons.

I think techies have been reusing from day 1 in the same way musicians have been reusing from day 1. Its an ongoing organic evolution and sythesis that will keep ongoing.

Doug T.
A: 

The two software projects I've worked on have both been long term development. One is about 10 years old, the other has been around for over 30 years, rewritten in a couple versions of Fortran along the way. Both make extensive reuse of code, but both rely very little on external tools or code libraries. DRY is a big mantra on the newer project, which is in C++ and lends itself more easily to doing that in practice.

Scottie T
+5  A: 

We reuse code - in fact, our developers specifically write code that can be reused in other projects. This has paid off quite nicely - we're able to start new projects quickly, and we iteratively harden our core libraries.

But one can't just write code and expect it to be re-used; code reuse requires communication among team members and other users so people know what code is available, and how to use it.

The following things are needed for code reuse to work effectively:

  • The code or library itself
  • Demand for the code across multiple projects or efforts
  • Communication of the code's features/capabilities
  • Instructions on how to use the code
  • A commitment to maintaining and improving the code over time
David
+1  A: 

Level of media attention to an issue has little to do with its importance, whether we're talking software development or politics! It's important to avoid wasting development effort by reinventing (or re-maintaining!) the wheel, but this is so well-known by now that an editor probably isn't going to get excited by another article on the subject.

Rather than looking at the number of current articles and blog posts as a measure of importance (or urgency) look at the concepts and buzz-phrases that have become classics or entered the jargon (another form of reuse!) For example, Google for uses of the DRY acronym for good discussion on the many forms of redundancy that can be eliminated in software and development processes.

There's also a role for mature judgment regarding costs of reuse vs. where the benefits are achieved. Some writers advocate waiting to worry about reuse until a second or third use actually emerges, rather than spending effort to generalize bit of code the first time it is written.

joel.neely
A: 

Maven has solved code reuse. I'm completely serious.

RogerV
Maven makes it quite easy to describe dependencies between software elements, but you still have to be aware of code duplication in the things you write.
Kwebble
A: 
Danny Varod
+1  A: 

My personal view, based on the practise in my company:

  • Do you or your company try and reuse code?

Obviously, if we have another piece of code that already fits our needs we will reuse it. We don't go out of our way to use square pegs in round holes though.

  • If so how and at what level, i.e. low level api, components or shared business logic? How do you or your company reuse code?

At every level. It is written into our coding standards that developers should always assume their code will be reused - even if in reality that is highly unlikely. See below

If your OO model is good, your API probably reflects your business domain, so reusable classes probably equates to reusable business logic without additional effort.

For actual reuse, one key point is knowing what code is already available. We resolve this by having everything documented in a central location. We just need a little discipline to ensure that the documentation is up-to-date and searchable in a meaningful way.

  • Does it work?

Yes, but not because of the potential or actual reuse! In reality, beyond a few core libraries and UI components, there isn't a large amount of reuse.

In my personal opinion, the real value is in making the code reusable. In doing so, aside from a hopefully cleaner API, the code will (a) be documented sufficiently for another developer to use it without trawling the source code, and (b) it will also be replaceable. These points are a great benefit to on-going software maintenance.

Stewart