views:

640

answers:

9

A few years ago, we needed a C++ IPC library for making function calls over TCP. We chose one and used it in our application. After a while, it became clear it didn't provide all functionality we needed. In the next version of our software, we threw the third party IPC library out and replaced it by one we wrote ourselves. From then on, I sometimes doubt whether this was a good decision, because it has proven to be quite a lot of work and it obviously felt like reinventing the wheel. So my question is: are there disadvantages to code reuse that justify this reinvention?

+2  A: 

P.S. The reasons for writing our own library were:

  • Evaluating external libraries is often very difficult and it takes a lot of time. Also, some problems only become visible after a thorough evaluation.
  • It made it possible to introduce some features that are specific for our project.
  • It is easier to do maintenance and to write extensions, as you know the library through and through.
Dimitri C.
you probably should have just updated your question, rather than adding an answer as an addendum.
Carson Myers
I haven't done so, because I then would be asking two questions: is duplicating an existing library sometimes justifiable, and was our rationale acceptable.
Dimitri C.
As a matter of fact, answering your own question is ok and even encouraged. If it's an answer, it should be written as an answer, no matter who writes it :-).
sleske
I'd say those reasons are justifiable.
HLGEM
+7  A: 

I can suggest a few

  1. The bugs get replicated - If you reuse a buggy code :)

  2. Sometimes it may add an additional overhead. As an example if you just need to do a simple thing it is not advisable to use a complex BIG library that implements the required feature.

  3. You might face with some licensing concerns.

  4. You may need to spend some time to learn\configure the external library. This may not be effective if the re-development takes a much lower time.

  5. Reusing a poorly documented library may get more time than expected/estimated

Chathuranga Chandrasekara
Which can be summed up as: "Only reuse code if it actually does what you need (and works)" :-)
sleske
bugs get contained too, not just replicated
Here Be Wolves
+2  A: 

It's pretty much always case by case. You have to look at the suitability and quality of what you're trying to reuse.

David Plumpton
+2  A: 

The number one issue is: you can only successfully reuse code if that code is GOOD code. If it was designed poorly, has bugs, or is very fragile then you'll run into the same issues you already did run into -- you have to go do it yourself anyway because it's so hard to modify the existing code.

However, if it's a third-party library that you are considering using that you don't have the source code for, it's a little different. You can try and get the source if it's that kind of library. Some commercial library vendors are open to suggestions and feature requests.

colithium
+1  A: 

The biggest disadvantage (you mention it yourself) by reusing third party libraries, is that you are strongly coupled and dependent to how that library works and how it's supposed to be used, unless you manage to create a middle interface layer that can take care of it.

But it's hard to create a generic interface, since replacing an existing library with another one, more or less requires that the new functionality works in similar ways. However, you can always rewrite the code using it, but that might be very hard and take a long time.

Another aspect is that if you reinvent the wheel, you have complete control over what's happening and you can do modifications as you see fit. This can be completely impossible if you are depending on a third part library being alive and constantly providing you with updates and bug fixes. On the other hand, reusing code this way enables you to focus on other things in your software, which sometimes might be the thing to do.

There's always a trade off.

Magnus Skog
A: 

Wondering what you are using to keep this library you reinvented?

What do you mean exactly?
Dimitri C.
You have a bunch of great code....how are you storing it, making it easy to find, helping the other developers find the right code to use? Like a wiki or project management site? Seems to be the most common way to store code for reuse.
+1  A: 

The Golden Wisdom :: It Has To Be Usable Before It Can Be Reusable.

AraK
+1  A: 

If your code relies on external resources and those go away, you may be crippling portions of many applications.

JasonBartholme
+1  A: 

Since most reused code comes from the internet, you run into all the issues with the Bathroom Wall of Code Atwood talks about. You can run into issues with insecure or unreliable borrowed code, and the more black boxed it is, the worse.

Chet