Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!rpi!clarkson!news.clarkson.edu!cline From: cline@cheetah.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c++ Subject: Re: libraries, compilers, class info, exceptions Message-ID: Date: 25 Sep 90 07:29:31 GMT References: <995@halley.UUCP> Sender: news@news.clarkson.edu Reply-To: cline@sun.soe.clarkson.edu (Marshall Cline) Organization: (I don't speak for the) ECE Dept, Clarkson Univ, Potsdam, NY Lines: 65 In-Reply-To: kelley@halley.UUCP's message of 24 Sep 90 16:10:24 GMT Nntp-Posting-Host: cheetah.ece.clarkson.edu In article <995@halley.UUCP> kelley@halley.UUCP (Michael Kelley) writes: >A couple of questions: >Does anyone know of a library of generic data structures (lists, trees, >associative arrays, etc.) with a parameterized interface in keeping with the >"template" syntax? I'm sure you're aware of libg++ by Doug Lea (it's had a pseudo-template mechanism for quite a while now). >What are your views on an appropriate name for a run-time function to return >class information? How about `0' :-) Runtime (weak) typing is wonderful if you want a toy language that will solve toy problems. Strong typing is nearly essential for programming in the large. Smalltalk provides runtime typing but does NOT provide any compile time typing. C++ is exactly the opposite, which is the real tragedy of translating Smalltalk-like libraries into C++. Ie: forget the speed hit. Forget the 2x to 3x more new/delete calls caused by the Smalltalk model. Forget the 2x more pointer dereferences, and just think about discarding the only ONLY **ONLY** type checking the language *gives* you. The Smalltalk library was designed for Smalltalk, but not for C++. Not to sound like I'm double minded or anything, but Keith Gorlen's NIHCL does a wonderful job of providing persistent objects. Ideally persistence should be buried in the language so as to avoid the temptation to check the type of an object at runtime for other purposes as well (it may sound trivial, but: you only need to check the type of a referenced object when you don't know the type, and that implies you're relying on weak typing). I wish C++ proper gave us persistence; that way no one would have to pay the horrible prices imposed by Smalltalk-like C++ libraries. >Linton suggested "dossier", but that sounded a little >too government-ish having grown up in Los Alamos. So, I've implemented the >"typeof" function. It can be used as both a function taking one argument, >or as a virtual member function taking no arguments. It's generated >solely from the object files prior to link time--no source code needed. >We're using it to cast down to virtually derived classes... Pointer casting is the goto of OOP. In structured programming, everything revolves around the control flow. Goto's can mess up the control flow, which messes up `everything'. In OOPLs, everything is in the `type' of the objects. Pointer casts can mess up the type, which messes up `everything'. There are a few places where the analogy breaks down (a wrong goto merely passes control down the wrong branch, but a wrong pointer cast can cause an arbitrary member variable to be treated as if it were the vptr! BOOM!). I think you'll find that the template mechanism will give you the kind of flexibility to conveniently support strong typing. You'll never (well... *almost* never) have to do a pointer cast. Marshall Cline -- ============================================================================== Marshall Cline / Asst.Prof / ECE Dept / Clarkson Univ / Potsdam, NY 13676 cline@sun.soe.clarkson.edu / Bitnet:BH0W@CLUTX / uunet!clutx.clarkson.edu!bh0w Voice: 315-268-3868 / Secretary: 315-268-6511 / FAX: 315-268-7600 Career search in progress; ECE faculty; research oriented; will send vita. PS: If your company is interested in on-site C++/OOD training, drop me a line! ==============================================================================