Tell me more ×
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 is a general question about programming, I hate using other people's code and I find myself coding things in my own way, even the simplest things like a web template, a PHP calendar, or a news module. Is there anything wrong with that ? Should I change and get in the habit of re-using other people's free code.

share|improve this question
Also see a more or less related question: programmers.stackexchange.com/questions/55374/… – MainMa Apr 8 '11 at 16:26

migrated from stackoverflow.com Apr 8 '11 at 15:18

8 Answers

The biggest disadvantages I have found of not re-using code are:

  1. It takes time which could be better spent implementing other things
  2. If the functionality someone else has written is well established, the likelihood of me implementing it better or with less bugs is low

Sometimes I find that a hybrid approach works well, at least with open source projects. I prefer using them rather than re-inventing the wheel, but I also will try to improve the code or fix problems I find in it, so that all effort is focused on making one useful resource for the community at large.

share|improve this answer
+1 for not reinventing the wheel. – rlb.usa Apr 8 '11 at 16:17
1  
NOTE: do make sure that the terms of the license for the code you want to use work with the project you are writing. You'll find a lot of GPL code, and a lot of overlap with BSD/ASL/MIT licensed code. It's a shame that there needs to be two different libraries for the same thing just because of the license model, but it is where we live. – Berin Loritsch Apr 8 '11 at 16:53

I would rewrite instead of reuse for the following reasons:

  1. It's core functionality, and I should have complete understanding and control of what goes into it.
  2. I only want a little bit of the functionality, and I don't want to pay for a learning curve for the whole thing.
  3. I don't understand how it works, and I have the space and time to figure it out.
  4. I can't find a library or framework that actually does what I need without stretching it beyond the intended use.
share|improve this answer

First of all, if you do not want to use other peoples code, you cannot by definition be a part of a team. This is a great hinderance as most non-trivial software projects are lifted by teams.

Then, if you want to do everything yourself, it takes longer (yes, it does) and you do not get the insight of others and at some point the maintenance burden gets too large for you to perform.

Hence, strongly reconsider your position. The view is better when you stand on the shoulders of others.

share|improve this answer

I have been taught in school that you should reuse unless you are in of the following categories:

  1. You are trying to learn how something works
  2. You can do it better
  3. You are not allowed to use an existing module

The first simply means, if you do not know how a parser works and what the challenges it overcomes, then write one yourself. This works for any technology that acts as a glue and for simple projects (like a calendar).

If you have come up with an algorithm that runs faster in the case that you'll most likely need it, then write your own. For example, if your calendar needs to cover multiple calendar types (think lunar and Gregorian), and you cannot find one already, then do it yourself. You should market the solution since other people will probably have the same problem.

Your company may not allow you to use a particular module based on the licence or other policy. In this case you can only really write your own library/system.

@jprete raises a good point in that core functionality should be implemented yourself. I argue that if there is a library/system that already exists that completes your core function, then your system may work better as glue that binds together multiple systems to enhance their behavior.

In all cases, you must make a conscious decision on whether you will write the functionality yourself or use a third-party library, and be able to argue your decision. Each project is unique and will force you to chose differently. Even the same project with different team members may imply a different choice.

Hope that helps.

share|improve this answer

This partly depends on what the piece of code does.

You should never write your own security code unless you know very well what you're doing, and you can get reviews by other people who are very experienced in security software and how to attack it. There's too many ways you can screw up and not realize it, even if you're very competent in general.

share|improve this answer

It honestly depends. Sometimes it's very good to do something once yourself, either because the existing way is too bloated, not exactly what you need, etc. Also sometimes reinventing the wheel is a really good way to learn something (try writing your own generic dictionary -- go ahead, you'll learn a lot). However if it's a matter of budget or time, it's often best to reuse. Usually there are more features than you could implement on your own, and your boss will (usually) thank you for it. Just make sure they're GOOD libraries worthy of the product they'll be placed in.

share|improve this answer

There is nothing wrong about hating using someone else's code in general. In most cases, the source code you find on the internet may not be very good. It doesn't match the standards, is not tested, is not readable, etc., which is especially true in PHP, where too many people writing code are inexperienced.

Creating a news module is not very hard. Finding an usable one, then finding how to use it (with no documentation available) may be much longer and difficult. Later, when your customer will ask you to make a small modification, if it's not your code, it will take you much longer, or will even be impossible to do.

On the other hand, don't rewrite just for rewriting. If you implement your own date-time methods instead of using ones already implemented in PHP, there will be a problem. If you invent your own cryptography algorithm for storing sensitive data instead of using existing ones, chances are that security issues will arise very quickly.

To conclude, it's ok if you write your own code because the code you can find suck from your point of view or require too much effort to work with. It's not ok if you write your own code just because you don't want to reuse.


In all cases, don't fall into the reuse syndrome: it's not because something was already written than you must reuse it at all costs. Some companies promote this approach (and in general tell you that the future of a developer consists of drag-dropping reusable blocks to create commercial products), but this approach of software development is neither realistic, nor serious.

share|improve this answer

Would not say this is the case for everything, but if you are spending time writing your own calendar control, then you probably are wasting some valuable time. There are loads of good calendars out there written by people who do nothing but make calendar controls all day for people to use, pretty much drag and drop. Unless you are one of those people, why not drag and drop the stuff that is not central to your application. There is always more to do that cannot be drag and dropped, so focussing on those things might make you significantly more productive.

share|improve this answer

Your Answer

 
discard

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