[Effective-cpp] Item 1: Choose Your Containers With Care

Paul Grenyer pjgrenyer at iee.org
Sat Jun 28 10:32:20 EDT 2003


On Sat, 2003-06-28 at 13:38, Robert W Hand wrote:

Hi Bob

> >Scott finishes the item with a list of questions aimed to help choose
> >the appropriate container. I think this could have been presented better
> >as a tree diagram where one question leads on from the next depending on
> >how it is answered and all branches lead finally to a container. I've
> >often thought this would be a good exercise for the Linux \ STL project.
> >If I get chance I'll knock up a diagram and a small application which
> >helps choose containers in this way.
> 
> I think that this is the crux of the article.  Scott wants us to stop 
> thinking about containers as "generic containers".  

I agree!

> I often see written a 
> comment that one can design and write a program without regard to the 
> container type.  The claim is that the programmer can switch from one 
> container to another type (say vector to list) at any time, perhaps in 
> response to performance issues that are noted during the testing 
> phase.  Scott's main point is that the container type is part of the design.

Again, I agree. I have seen it written that containers are
interchangeable in a number of books. However, experience has show they
are not. Especially, for example, changing from vector to list when
sorting or operator[] access is involved.

> So I would be interested in seeing your decision tree, but I think that 
> Scott is trying to get us to think about container types in the design 
> phase.  Such thinking should not be too mechanical.

I'm a little concerned about your use of the word 'but' above. My tree
would certainly be used in the design stage. I can see however how such
a tree might make things mechanical. However, if the questions are good
enough (and I think Scott's will prove to be), then a tree like the one
I describe should be an aid to new and experienced programmers alike
(not that I'm building it up or anything. ;-) ).

> Nice review.

Thanks!

Regards
Paul

PS: Can we dispense with the jokes about chopping down the tree I've
build-up, please? :-)





More information about the Effective-cpp mailing list