Re: Question about programming techniques



Miroslav Silovic wrote:

> Excuse me... what 'power'? Aside from the fact that MICO owes much of
> its uselessness to STL, you elegantly avoided Dirk's simple question;
> and the answer to it is: You can't.

STL is far from useless.  The container classes are sufficiently 
generic to contain pretty much any type of class you wish to 
stuff into it.  The algorithms work on all container types, for
any object in them.  The iterator interface is also great for 
manipulating data where the algorithms are insufficient.  Also makes
changing from a list to a vector, or a map to a set painless.

> STL forbids mixed-type containers. That, IMHO, disqualifies it from
> consideration for serious projects.

1) The overwhelming majority of the time, containers hold objects
which are all of the same type, or derived from a common base class.
Make your containers hold pointers to the common base, and you're set.

2) If you are storing mixed types in a container, you *need* to know
what type they are on extraction.  You can derive all objects from
a Containable base class and use dynamic_cast<> to ensure the object
you extracted is of a compatible type.  This is much safer than a 
straight typecast.

> And if you want to link them with C libraries (ones that weren't
> compiled with C++ compiler), you have to a) doctor the headers for
> extern "C" declarations, 

a) Unless you wish to restrict everyone who uses such a library from 
using C++, adding the #ifdef __cplusplus \ extern "C" { \ #endif
and the correspnding closing brace to the headers is trivial.

> b) forget about passing typechecked stuff to
> C, and cast everything into void*, 

b) depends on what you hope to accomplish in C. I haven't found 
much of a need for it in my day to day programming.

> c) hope that C++ won't bump some of
> the pointers to something you didn't want during the cast.
> 
> c), BTW, gave me tons of grief. I was reduced to ripping vtable
> pointers out of object records on one occasion. :P Thankfully, I
> haven't had to try to compile that stuff with anything other than g++.

c) again, i haven't seen this, although i wouldn't put it past C++.

I don't wish to start a C/C++ language war here. I merely wished 
to correct some of the perceptions voiced above. Both C and C++
are tools.  They can be used efficiently, or inefficiently, for 
good, or evil.  Each has advantages and disadvantages, and I
usrge you to know your territory before deciding to implement code
in either one.  Picking the right weapon can make the battle much
easier.

>         Miro

-- ebm
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+
|  __                         a.k.a. Eric B. Mitchell |
|  |_) .  _  _|      _|  _     ericmit@ix.netcom.com  |
|  | \ ( (_ (_| (_| (_| (/_   www.netcom.com/~ericmit |
| How's My Programming?   Call:  1 - 800 - DEV - NULL |
+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]