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.

This question already has an answer here:

As per this question: I decided to implement the BitTorrent spec to make my own client/tracker.

Now, I was going through the spec, I was about 70% done implementing the BEncoding when I found a link to an implementation of BEncoding in C# written by someone else.

Normally, if I were working on production code, I'd use it as a reference to check my own work against, and a baseline to write some tests to run my code against, but I found myself thinking "I'm making this, it's a for-fun project with no deadlines; I should really implement it myself - I could learn a lot" but some voice in my head was saying "Why bother re-inventing the wheel? Take the code, work it so that it's you're style/naming convention and you're done."

So I'm a bit conflicted. I ended up doing the latter, and some parts of it I found better than what I had written, but I almost feel like I 'cheated'.

What's your take? Is it cheating myself? Perfectly normal? A missed opportunity to learn on my own? A good opportunity to have learned from someone else's example?

share|improve this question
It just so happens that I wrote my own passable (barely..) BEncoding parser. I learned a lot from doing it. –  ChaosPandion Sep 27 '10 at 1:22
Don't reinvent the wheel. Use Ctrl + C, Ctrl + V –  pramodc84 Sep 28 '10 at 4:11
If you can vote and think this is a useful question or it have useful answers below, please vote up. StackExchange sites need votes to build a good community. You can give 30 votes per day, don't waste them. Specially users with high reputation and low counting votes given please read this: meta.programmers.stackexchange.com/questions/393/… –  bigown Oct 5 '10 at 22:28
add comment

marked as duplicate by gnat, MichaelT, GlenH7, Dan Pichelman, mattnz Sep 10 '13 at 8:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

9 Answers

up vote 22 down vote accepted

If I have seen further it is by standing on the shoulders of giants.

Isaac Newton

It is not cheating if the code is open source and you've taken the time to understand it. Now obviously this isn't always possible due to time constraints but try and always have high level overview of the code you are using. Always remember that C was derived from B.

share|improve this answer
add comment

Copy from one, it's plagiarism; copy from two, it's research.

A good listener is not only popular everywhere, but after a while he gets to know something.

In other words, copy all you want, but learn something from it as well. No great researcher/scientist/engineer ever got anywhere by relying on his own work only.

share|improve this answer
add comment

Whereas Newton could say, "If I have seen a little farther than others, it is because I have stood on the shoulders of giants," I am forced to say, "Today we stand on each other's feet." Perhaps the central problem we face in all of computer science is how we are to get to the situation where we build on top of the work of others rather than redoing so much of it in a trivially different way.

  — R.W. Hamming, 1968 Turing Award lecture [emphasis mine]

share|improve this answer
add comment

In that situation it really depends on how you feel about it. I went through a couple things and made them Markdown compliant. Did I re-write the markdown parser in PHP? Nope, borrowed someone else's. I also added PDF conversions. Did I write my own PDF converter? One look at Zend_PDF documentation made me want to run screaming to the hills, so I will confess again to using someone else's code.

If the expectation is a learning process I would use it as a guide. Write your own, and then compare. Use the comparison to improve your own code.

share|improve this answer
add comment

well here's my 2 cents ... Why do colleges insist that students write their own hashtables, linklists, arrays, etc. instead of allowing them to use existing libraries? 1) so that they'll understand the underlying concepts of those data structures ...

But, as a professional developer, i'm all for not reinventing the wheel, unless you're learning something new, or improving the current "wheel". I'm all for learning from other people's code because sometimes i don't have time to write a new library, or sometimes i just need a functional module without knowing its inner working ... like i drive a car without really understanding all the machinery ...

But, for personal enrichment - well it's totally up to you :P. Learn as much as you can while not reinventing the wheel would be a good principal. Or ... come up with something that replaces the wheel ...

share|improve this answer
Like antigravity? –  Michael K Nov 12 '10 at 15:03
add comment

You are using C#, so I assume you are already using a framework (.Net or Mono). The .Net Framework comes with a lot of things already done for you (for example the tcp communication), and I'm sure you also copy some code snippets you find in some sites like stackoverflow.com, so, why reinventing the wheel?

Furthermore, you already learnt enough (by doing the 70% by yourself) to understand the other guy's code and to realize that it was better than yours in some points.

If the code fits your needs and is open source then take it. But, on the other hand, what I would not do is to change the code to make it more like yours. Add your comments, set some headers to know where did you extract the code from, but don't modify it if you cannot enhance it.

share|improve this answer
add comment

"The best code is the code that you don't have to write." - Unknown

If the code is free to use and the license terms are suitable for what you will be using it for, then what's the problem?

Using other people's code is a great way to save time and effort, and as long as you're doing it legally I think only good things can come of it.

share|improve this answer
add comment

The best way to answer this question is to evaluate your goals. Why did you start this pet project of yours?

Did you want to learn the technology, or experiment with a new language, or a new technique? If so, write your own.

Or did you start because you wanted a working final product? Does the project fill some need of yours? If so, borrow and borrow often.

share|improve this answer
Good answer, it 100% depends on why SnOrfus was writing this client. –  Carson63000 Oct 12 '10 at 1:02
add comment

My answer will be biased from my point for sure but using code from other people is like playing with a black box: you know the input and the output, but you don't know whats going on at all but there's something also true: you don't need to reinvent the wheel everyday

Depending on how it was written the third party code it can also draw a line with a warning "from here we enter the domain of the unknown consequences"

share|improve this answer
This is true of a compiled executable/library, but NOT of a piece of code - if you've got the source you can read exactly what it is doing, so it is not a black box. –  Peter Boughton Sep 27 '10 at 17:19
It is also partially true for scripting languages.. Are you telling me that you're really going to read that huge and bloated library when you're in a pinch and need to meet the dates? It happened to me with third party PHP classes they were written in a so messy way that I did not even dare to understand how it was done it just worked for me and I'd bother later when i had more time. For code snippets you can take your time and see what it does, even spend a few minutes removing redundant code/optimized –  rmontagud Sep 28 '10 at 8:17
add comment

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