Article View: comp.std.c++
Article #1938Re: STL find errorprone
From: John Max Skaller
Date: Sat, 09 Sep 1995 18:04
Date: Sat, 09 Sep 1995 18:04
84 lines
3514 bytes
3514 bytes
ajay@lehman.com (Ajay Kamdar) wrote:
>In article <DED5p2.I2I@online.tmx.com.au>,
>Tony Cook <tony@online.tmx.com.au> wrote:
>>I've been using the STL a little recently and can't really call
>>myself an expert - but I've found that always typing in the
>>container's name up to three times for a find or twice for other
>>actions is getting a little error-prone, for example:
>
> [ Example and suggested alternative ellided ]
>
>
>Join the club(: You will find many who will agree that STL is
>error prone to use. I am sure it's a cool and efficient design,
>but IMHO not enough attention has been paid to make it easy to use.
>
>>One argument against this is 'the programmer can write their own' -
>>but this is true for most things - the libraries are there to
>>provide a useful (and hopefully less error-prone) implementation so
>>the programmer doesn't have to write their own.
>
>I couldn't agree more.
>
>Even before the ink is dry on the DWP, commercial vendors of STL
>implementations are already extending STL in incompatible ways to fix
>these STL usage problems.
Unfortunately, there are some misconceptions about STL.
One is that is OUGHT to be "user friendly".
Nope. STL is a LOW LEVEL TOOLKIT, akin to the ISO C Standard
Library. For example "copy()" is equivalent to "memcpy()".
Now, you wouldn't recommend using "memcpy()" in the middle of
an applications program, would you???
To make STL into a "user friendly" library is a silly idea.
Instead, the idea is to use STL to implement a completely separate
application library.
For example, consider the type "SET OF T". Would you use
the STL set container for this?? You have to be kidding!
template<class T> class MathSet {
set<T, less<T> > data; // USE STL to implement robust point set
public:
MathSet() {}
...
friend bool operator < .... // note: NOT STL compare!
Mathset operator | ..... // Union
Mathset operator & ..... // Intersection
...
.. getFirst()const { if(data.empty()) throw EMPTYSET().. }
}
This is what I want from a set ADT. Implementing it is EASY
using STL -- and THAT is the purpose of STL.
If you're getting bored writing
find(longContainerName.begin(), longContainerName.end() ...... )
.. you're probably using STL the wrong way.
BTW: Continue to do so! The only way to discover how to use
something well probably entails learning how to use it badly too.
I've had exactly the same kinds of problems -- but I have to
attribute them to my own level of comprehension, not STL.
--
John Max Skaller voice: 61-2-566-2189
81 Glebe Point Rd fax: 61-2-660-0850
GLEBE NSW 2037 email: maxtal@suphys.physics.oz.au
AUSTRALIA email: skaller@maxtal.com.au
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<MATT.95Sep9110458@physics10.Berkeley.EDU>Path:
arc1-ca.pugleaf.net!128.32.155.1!mattReferences:
<DED5p2.I2I@online.tmx.com.au> <42hjvb$bj5@jabba.lehman.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!128.32.155.1!matt From: John Max Skaller <maxtal@suphys.physics.su.oz.au> Newsgroups: comp.std.c++ Subject: Re: STL find errorprone Date: 09 Sep 1995 18:04:58 GMT Organization: MAXTAL Approved: matt@physics10.Berkeley.EDU (Matt Austern) Message-ID: <MATT.95Sep9110458@physics10.Berkeley.EDU> References: <DED5p2.I2I@online.tmx.com.au> <42hjvb$bj5@jabba.lehman.com> NNTP-Posting-Host: physics10.berkeley.edu