So one should avoid stl containers just
because it’s not a good practice to put pointers inside them ?
I think it’s just a matter of words here. For the guy who asked
the question in the first place, it can be quite confusing to read this.
Again, we may all agree but I don’t like the “good practice” or
"bad practice" approach because it highly depends on the knowledge
and experience of each other.
That’s also the reason why I posted a little bunch of code with a plain
old school array of pointers, which led to a debate on stl containers
just because he said he was doing C++ programming …
Guys, again, this is a very general remark and brings nothing more
to the debate, but each tool is made for a particular purpose,
and in some cases stl containers are better, even with pointers in it,
and in other cases arrays are the best (at least, you know what’s going
on for you have to do everything by yourself).
I dont’ see it as a bad practice at all. If you read the stl documentation
(what you should do in the first place …), you will know what’s happening
when a container gets destroyed and then you’ll know that a leak could
occur if you’re not careful. Else, either the guy was too in a hurry and should
avoid computer programming, or he should learn C/C++ first.
Then, where is the bad practice here, stl are templates, so they
allow for putting what one wants inside, and nobody said that pointers
should be avoided. B.Stroustrup is not the god of programming, btw.
The real problem here is not good practices or STL or whatever, it’s more
how the C++ language itself is built. It pretends beeing object while still
beeing unclear and allowing everything to happen, which is both practical and
a problem. If one really wants a clear language, with a smart memory management
policy, one could try Objective C instead. This is the language behing OpenStep and
more recently Mac OS X::Cocoa.
So, Simon, it’s not a personal attack. I’m rather making a remark on the words
you used. Instead of talking about what’s “good” or “bad” better showing
the advantages and drawbacks of the technics, which allows the reader to
make its own judgement based on his degree of understanding. Good and bad
is a way to cut off good reflexion and constructive debate, IMHO. Like what has been
said, we could list a lot of useful tools/technics which are considered as bad practice
like mutual referencement (through pointers), gotos (try writing a parser in plain C without
gotos, what a pain), etc.
Btw I personally use stl containers of pointers and I really appreciate to
have the power of those containers, and clearly understand what’s happening
with them, so — no danger in using std::vector<SDL_Surface*> —
Off-Topic, can someone point me to a good book on the architecture of modern
computer graphics ? (not opengl red book/orange book, but something really
oriented architecture, memory, etc.)
Regards,
Julien CLEMENT.
<<<
No, check my previous post. Chris had already pointed out thatstd::vector<SDL_Surface> would be wrong and I acknoledged it, but I
still maintain that a container of pointers is not a good practice.>>>