5

As I have been learning to program, be it in my intern-ship or school, I have often come across situations where an extra piece of software is needed (from fairly basic to quite complex) and I am almost always told that I shouldn't waste my time developing a solution and use something someone else has already done.

Does it make sense to do this or should I take the time to research and develop my own? At the moment I'm doing my final project which I have 15 weeks to complete, but the tutor and my classmates tell me not to bother. I can't help but think I am letting opportunities pass me by.

4
  • 10
    The natural tendency for most programmers seems to be to write their own implementation rather than try to understand someone else's. This inclination is bad and dangerous.
    – TehShrike
    Jan 14, 2013 at 0:19
  • 3
    @TehShrike I agree, but/and I think this is a process every programmer has to go through (I will write my own better version!) before learning to become smart and lazy in a good way (let's check first if someone has wrote that before coding it) :-)
    – Jalayn
    Jan 14, 2013 at 10:04
  • The last sentence is not too clear. They tell you not to bother developing your own or not to bother using the existing.
    – Jan Hudec
    Jan 14, 2013 at 10:04
  • @Jalayn Couldn't agree more. Jan 14, 2013 at 20:11

7 Answers 7

5

Wow that's a really tough question and to be honest there is no right or wrong answer. Almost every programmer has their own way of programming and therefore learning/improving their skills. I would say there are mainly four different stages in learning how to code and when/why you have to use modules/plugins/frameworks:

  1. If you are at the very beginning of your programming career you have to learn to write code yourself. You have to play with the language to get a feeling of what is possible and what is not and also to get a glimpse of what patterns are, where they occur and how to use them.

  2. At a certain stage after you discovered the basics of what programming means you are ready to use existing modules/plugins/frameworks. It's a necessity to learn how to read and use other peoples' code. Learn where and how patterns were applied to code others have written. Main goal of this stage is to learn that modules/plugins/frameworks can ease your daily work but also that not every module/plugin/framework is worth using.

  3. At the same time you are mastering the second stage you are about to enter the third one. Reproduction! You will not only use modules/plugins/frameworks, you have to understand/reproduce them in order to use them or even alter them to contribute back. Almost every time you will use other peoples' code you will extract and reproduce the details you are interested in.

  4. Never ever fully rely on frameworks others have written. From time to time you will recognize anti-patterns or just poorly written code (not to mention errors). Even if you do not expect it almost every module/plugin/framework has errors and/or misbehavior (sometimes the documentation is not matching the actual code).

    So the last stage of learning how to program and use modules/plugins/frameworks is to write them on your own. You can see it as a good exercise to do some of the things a module/plugin/framework could provide on your own. Sometimes this will help you to fully understand code others wrote.

To answer your question you have to clarify for yourself at which stage you are with your programming skills and, as it seems, what the goal of your final project is. Is it about creating a functional application than uses "as many" modules/plugins/frameworks as there are to ease your work. However if this is an educational task most often it is not about creating an application but rather learning the way to do the job. The question what your tutor expects can only be answered by him, so go and ask.

PS: Good luck.

1
  • You are welcome. The question reminded me of my own final exam where similar questions had arisen. I'm glad to be of help.
    – wagnerpeer
    Jan 15, 2013 at 6:58
7

If you have little time to complete a project, it's a good idea to use third-party code. The only thing is to understand how it works (in the level of interfaces) in order to use it correctly and not to get any "surprises".

The most rational approach, I think, is to use the third-party code and complete your project. If after that you have time left, you could start developing your own code and replacing the third-party code with yours. You could start with the most interesting/difficult/challenging pieces. And you could leave the ones that are based, for example, on covering many various and obvious cases (like a calendar drop-downs). This way you would avoid the risk of not having the project done on time.

When developing your code and replacing the third-party one with it, you could study the techniques used in those codes and try to improve them. Besides, there are libraries which are very efficient and beautifully designed, so studying them would be much more useful than creating the same functionality by yourself.

2
  • That sounds like great advice. Jan 14, 2013 at 15:26
  • 1
    @gnat, thanks for the edit. I just can't memorize when to use its or it's (((
    – superM
    Jan 14, 2013 at 19:41
4

If you need to get a job done (and your final project probably counts as "a job" in that context) then the approach I tend to use is to write the code that is crucial to the problem at hand and use libraries where it saves me time and isn't core to the problem.

For example importing a CSV file can be a surprisingly complex problem to solve properly, if you have to deal with all the subtleties of character encoding, embedded line breaks, nested quotation marks, badly formatted data etc. It's also (usually) not something that is of special business importance, it's just "something that needs to be done".

In that case I'd find a library, use it and move on to something more important rather than waste my time reinventing the wheel.

That's not to say that it might not be interesting, or instructive, or just plain fun to do those "non-core" things yourself and you'll probably learn a lot by doing them but you have to learn to pick your battles. Prioritising what is important will help you determine what you need to write yourself, and what you can bring in from other sources.

2

Reuse existing code if and whenever possible.

Reading and understanding other people's code is important part of learning to be a programmer.

Other people's code is a great source of idioms you can use in your own work. If you just try to solve the problem yourself, you'll no doubt get it working, and you'll get more proficient with the techniques you already know, but you are unlikely to learn new techniques. And textbooks usually limit themselves to short examples and thus limited set of idioms.

By trying to understand other people's code you'll also see what is easy to understand. The assignments you get when learning generally don't include maintenance, so you don't get to look at the code you wrote a year later to see whether you can still understand it, but in practice you'll need that rather often. So other people's code can give you some sense about what to use and what to avoid to keep the code understandable.

It is also an important skill of it's own, since when you start doing programming for living, you'll most of the time work in a team and most of the time work on application that at least in part existed before you came, so you'll have to understand lot of existing code.

Therefore I suggest using existing code, unless it contradicts the assignment, of course. And taking time to understand first how to use it properly and than also trying to understand how it works.

2
  • As history shows, you can still do it your own way, after you've read other people's code and be successful with it.
    – ott--
    Jan 14, 2013 at 12:28
  • @ott--: Sure you can. And you know what you didn't like about their attempts, so it even has a better chance of being worth it.
    – Jan Hudec
    Jan 14, 2013 at 12:33
2

Priorities. Focus on what you want to achieve and in how much time. Yes, I'ts natural to have thoughts that certain building block could have been better, if I do it myself. But keep in mind that'd take you away from primary goal and project demands.

Re-use what's available and popular. Popular available components are used, tested and contributed to, by many-many developers (probably smarter than us). You can contribute too, a lot of It can be better opportunities are there. If it doesn't exists, create and share.

Finally, don't just re-use without knowing it. If you use external code, take some time to peek inside and see how stuff works. You'd learn a lot.

2

If we're talking about a school project, I generally think that most of the code should be your own. I think that productivity is not the most important think in this stage.

I'd decide for each problem individually depending on the scale of the problem and how the problem is related to your assignment.

For example when I was making a game as a school project (Breakout clone with more complicated physics) I did write the physics engine myself, because it was essential part of the assignment and I've learned something from it. However I didn't write the XML Serializer because it could be a project on its own and it isn't related to the assignment much.

2

I'll try to give a slightly different angle to the answers already given.

My main claim, and this is what takes some getting used to, conceptually, is that in most cases writing code is not the goal. Writing code is the means to an end. In most cases, the end is to get a software product out, getting it out with good quality, and getting it out in time. If writing your own code will get in the way of that (and it will. For practically all non-trivial cases, your own code will take longer to write and will be less well tested), than use existing libraries, because writing code is not the goal.

There are, of course, always secondary goals. Learning and improving as a developer is one of them. Developing in-house expertise in a problem domain or a technology may be another. These must all be considered when deciding whether to use existing code or write new code.

If your project is writing a new tool for market trend analysis, it doesn't make sense to use existing data-analysis code, since that's where you want your designers and coders to give the edge over the competition. But it does't make sense to write your own UI controls, since that's not what your users will be choosing you for.

But if you're writing a new eCommerce platform, it makes sense to use existing components for user management, data access and payment gateways, since these are commodities, and probably not the deciding factors - but do write your own UI, since the ease of use for customers and sellers is the main advantage you can offer.

And finally, the school project. You have two goals here: the first is to learn. The second is to pass and get a good grade. These two are related, but not identical, and occasionaly even contradictory. If you spend your 15 weeks developing your own tools and plugins, you will likely not be spending them doing the actual tasks you were charged with. Always remember that it's the product requirements, not the elegance of your code, that matter to those who order the project.

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