Reinventing the wheel

Posted on 2005-04-11
Last Modified: 2010-04-01
i have heard this many times ...... " About Reinveting The Wheel "

dont use linklists and arrays , insted use the STL

dont try to build an Operating System it will never be widely accepted ( which is true of course)

but isnt creating your own datastructures an excellent programming practice. i have read that one way of using the STL is to enhance it. the only way i know i can enhance it is by getting a good working knowledge of basic data structures and only way i can do that is by creating my own.

lets see what u guys have to say about it .......
Question by:furqanchandio
    LVL 19

    Accepted Solution

    Yeah I would agree with you that building your own data structures is "excellent programming practice", but that is all it is.  Practice.  If you have a deadline for a project that you are working on, and desperately need some efficient, resizable data structure (say), would you waste time writing your own one, or would you use the STL ?

    You can enhance the STL to some extent by deriving your own classes from it if required.  This may prove beneifical, depending on what you are trying to do.  I have never come across a need for this however.

    As you get more experienced you will know when to use your own code against using something that already exists.

    It boils down to "Putting what you know into practice" (using whatever means you know of to solve a problem) or "practising what you dont fully know" (which could be writing your own code, or could be using someone else's just to gain experience in it).

    LVL 22

    Assisted Solution

    It can be a hard decision.

    Often the only way is to try the already-existing framework and see if it does what you need, and does it in an efficient enough way.

    But quite often you end up fighting the tool, to the point where it's more of a hindrance than a help.

    A good example is: using a shell script instead of writing a program.

    You can often combine a few calls to grep and awk and Perl to do something in ten lines of shell script, that would take hundreds of lines of C++ code.  That's fine, but the script may be too slow, or too flaky, or have too many unwanted side-effects.  Then it may be time to start over using another approach.  

    Or maybe the canned approach is to big or too slow.  Oftent the onlly way to find out is to try the high-level approach.  Sometimes the results are really miserable.  Sometimes they're quite usable.  Sometimes you just happen to find the perfect match and the canned code runs very quickly and smoothly.   That's why I'm always pissed when the boss asks "When is it going to be done"?     Might be done in 5 minutes, or we may have to start over and take another month.

    You'll probably know when this is-- it's when you are cursing more at the "helper" code than you are making progress.  

    LVL 32

    Expert Comment

    I agree generally with the other posts. If you have the time you will learn a lot by doing it yourself. In the real world, however....
    LVL 4

    Author Comment

    how can equally distrubute points here ??
    LVL 19

    Expert Comment

    Heh, you can't.  

    And I for one am not going to quibble over 20 points; the important thing is you got the info you were after :)

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
    This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
    The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now