What are the disadvantages of code reuse?

A few years ago, we needed a C ++ IPC library to make function calls over TCP. We chose one and used it in our application. After some time, it became clear that it does not provide all the functions we need. In the next version of our software, we dropped the third-party IPC library and replaced it with the one we wrote . Since then, I sometimes doubt whether this was a good decision, because it turned out to be quite a lot of work, and it seemed to me that it was reinventing the wheel . So my question is: are there any flaws in code reuse that justify this rethinking?

+4
source share
11 answers

The biggest drawback (you mention it yourself) when reusing third-party libraries is that you are heavily connected and dependent on how this library works and how it should be used, unless you can create an intermediate level interface that can take care of it.

But it is difficult to create a common interface, since replacing an existing library with another one more or less requires that the new functionality work in a similar way. However, you can always rewrite the code using it, but it can be very difficult and time consuming.

Another aspect is that if you reinvent the wheel, you have full control over what is happening and you can make changes as you wish. This can be completely impossible if you depend on the library of the third part and constantly provide you with updates and bug fixes. On the other hand, reusing code in this way allows you to focus on other things in your software, which can sometimes be something to do.

There is always a compromise.

+1
source

I can offer several

  • Errors are replicated - if you reuse the buggy code :)

  • Sometimes this can add extra overhead. As an example, if you just need to do a simple thing, it is not recommended to use the complex BIG library, which implements the required function.

  • You may encounter some licensing issues.

  • You may need to spend some time studying / setting up an external library. This may be ineffective if re-development takes much less time.

  • Reusing a poorly documented library may take longer than expected / appreciated

+8
source

PS The reasons for writing our own library were:

  • Evaluating external libraries is often very complex and time consuming. In addition, some problems become noticeable only after a thorough assessment.
  • This allowed us to introduce some features specific to our project.
  • It’s easier to maintain and write extensions, since you know the library through.
+2
source

This is almost always the case. You should look at the suitability and quality of what you are trying to reuse.

+2
source

Problem number one: you can successfully reuse a code if that code is GOOD code. If it was designed poorly, has errors, or is very fragile, then you will encounter the same problems that you have already encountered - you still have to do it yourself, because it is so difficult to modify existing code.

However, if this is a third-party library that you plan to use for which you do not have source code, this is slightly different. You can try and get the source if it is such a library. Some vendors of commercial libraries are open to suggestions and feature requests.

+2
source

Golden Wisdom :: It must be useful before it can be reused.

+1
source

If your code depends on external resources, and those that go away, you can damage many applications.

+1
source

Since most code reuse comes from the Internet, you run into all the problems with Wall Wall of Code . This is evidenced by Atwood. You may run into problems with unsafe or unreliable borrowed code, and even more so the black box, the worse.

+1
source

Disadvantages of code reuse:

  • Debugging takes a lot longer because it is not your code, and it is probably a bit bloated code.
  • Any specific requirements will also require more work, as you are limited by the code you reuse and you will have to circumvent the restrictions.
  • Reusing constant code will lead to a long run in bloated and disorganized applications with difficulties in tracking errors - hell programming.
  • Reusing the code (depending on the case) reduces the problem and the satisfaction rate for the programmer, and also misses the opportunity to develop new skills.

It depends on the case, language, and code that you want to reuse or rewrite. In general, I believe that at a higher level, the language, the more I tend to reuse code. Mistakes in a higher level language can have a greater impact and are easier to rewrite. High-level code should remain readable, neat and flexible. Of course, this can be said about all the code, but somehow, rewriting the C library does not sound as good as rewriting (or rather, re-factoring) the code of the PHP model.

Somehow, these are some of the arguments that I would use to promote "reinvent the wheel."

Sometimes this happens faster, more fun and better to end up rewriting from scratch than working with bugs and limiting the current code base.

+1
source

Want to know what you are using to save this library again?

0
source
  1. The initial time to create reusable code is more expensive, and the time is more expensive
  2. When an update appears in the main branch, you need to synchronize it and deploy it again
  3. Errors are repeated - if you reuse the wrong code
  4. Reusing poorly documented code may take longer than expected / evaluated
0
source

All Articles