Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm working on a large class and started implementing new features that need graphics. I started writing the graphics functions myself, but I know that open source libraries exist that can provide me with this functionality without me having to write it myself.

The problem is that I prefer the class to be self-sufficient and not dependent on any other library. If I don't write it myself, I would have to ask the user to make sure a graphics library is already installed (less user-friendly). If I write it myself, I do a lot more work than I have to. I could also copy/paste some of the relevant code into my own class, but not sure about the disadvantages of doing this (it's an open source library that matches my license, so I'm not concerned with legality, just programming-wise if there are disadvantages).

So what should I do:

  • copy paste code from the external library
  • write the code myself so it's truly self-sufficient
  • ask the user to download and install another library
share|improve this question

migrated from stackoverflow.com Jan 9 '11 at 10:02

This question came from our site for professional and enthusiast programmers.

Subjective questions like this belong on Programmers.SE. –  user8 Jan 7 '11 at 7:33

3 Answers 3

Most opensource libs allow you to publish them together with your own code. You can bundle your class with all the code required to run it.

If you just cut out and modify pieces you can run into serious issues if the user wants to include the lib in the future.

Please keep in mind that in object oriented programming every class should have a clearly defined role. If your class has multiple roles and does many things you should probably break it in many different classes.

Having one "self sufficient" block is absolutly NOT desireable!

share|improve this answer

I think if it's a relatively small piece of code that you need (say less than 300 lines) and you can understand all the code your copying and pasting it's fine to do so and avoids the problems your mentioning however if there's a possibility that new features would be added or bugs would be fixed that you could benefit from then just using a reference to the library would be better, I think this is another kind of question that depends a lot on the particulars of the scenario. Copying and pasting is bad practice if you're doing it a lot within your own code base because it means your not properly re-using or arranging the communication between your objects, but copying from somewhere else so long as you understand the code and it's legal is fine IMHO.

share|improve this answer

I would not say disadvantage because you can see and use the code as you like. But I would rather say slight difficulty as you haven't created that library yourself, you would have to research and study the code to understand how it is working, so that you can modify it as you like(i.e. if you are authorised to modify the code).

But, actually it depends on how you intend to use the code

  • If the featured in the library is enough for you then just COPY / Paste
  • If you only want some features from that library, then study the code and extract the particular piece and update your own library, that is much better


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.