Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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]

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.

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.

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 ...

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.

"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.

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"

Licensed under: CC-BY-SA with attribution
scroll top