Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!rpi!clarkson!news.clarkson.edu!cline From: cline@cheetah.ece.clarkson.edu (Marshall Cline) Newsgroups: comp.lang.c++ Subject: Re: Why ask an object its type?? (was: libraries, compilers, class...) Message-ID: Date: 5 Oct 90 01:40:43 GMT References: <995@halley.UUCP> <57751@microsoft.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: 34 In-Reply-To: cline@cheetah.ece.clarkson.edu's message of 4 Oct 90 14:19:42 Nntp-Posting-Host: cheetah.ece.clarkson.edu In article cline@cheetah.ece.clarkson.edu (Marshall Cline) writes: >I'd like to ask a key question: ``WHY ASK AN OBJECT ITS TYPE?'' I failed to give the most obvious answer: ``because you don't know its type'' This is the crux of the strong vs weak typing issue. Ie: if you *need* to know more type information than can be statically determined, then you *need* some sort of CRO (class related object). But if you need more type information than is statically determinable, your program is weakly typed by definition, since it relies on dynamic type checks. A (good) example of where this is needed is persistence: you don't/can't know the type of the object at compile-time, so you *need* some help from the runtime. One solution is to do the type verification at the moment you read the thing in; Ie: tell the persistent storage device ``I the programmer believe the next object you'll hand me is a Foible [or some subtype thereof], and I expect you to holler at me right now if it's not.'' The persistent storage device gives you a *typed* handle (probably a wide ptr) to the Foible, and from that point on you can use it in a statically verifiable (strongly typed) manner. [ NB: The idea of dynamic typing upon reading an object certainly isn't original with me. Doug Lea and I have discussed the matter, and we got it from at least one published reference, but I don't have the reference handy (which means: ``Duh... I forgot'' :-) ] Marshall Cline -- PS: If your company is interested in on-site C++/OOD training, drop me a line! PPS: Career search in progress; ECE faculty; research oriented; will send vita. -- 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