Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!decwrl!megatest!djones From: djones@megatest.UUCP (Dave Jones) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things... Message-ID: <19131@prometheus.megatest.UUCP> Date: 24 Jun 91 23:28:33 GMT References: <2865E7A8.179A@tct.com> Organization: Megatest Corporation, San Jose, Ca Lines: 51 From article <2865E7A8.179A@tct.com>, by chip@tct.com (Chip Salzenberg): > Better pedantic than unsafe. ... and I had rather live in a house than stick beens in my ears. But it's not an exclusive choice is it? I'm really not desperately worried about the pointer-casting business. Casting a void* to the wrong type is very unlikely to can cause disasters in released code -- not if one does even rudimentary testing. I've been in this business for more years than I like to admit, and I've not yet seen this kind of mistake make it into a release. What it can do is get you into a difficult debugging session if you don't spot-test your new code frequently enough while you're developing it. I have found that such problems can be almost completely avoided by simply declaring in a comment, at the point where the object is declared, what type of pointers are stored in the container. When in doubt, you just find the declaration and read the comment. Still, one would prefer to have the process automated by the compiler, which is what prompted this discussion. > ... Never design code that requires downcasts. > Or, in other words: if the static type is important, why worry > about regaining it? Don't lose it in the first place. Something tells me this has all been hashed over previously. The "static type" was not "lost" in the first place. It did not exist in the first place. The generic container-class may have been written years before the application's type was defined. > Use templates. > If real templates are unavailable, use the preprocessor. That's what I have ended up doing. I've written macros. But to make the derived classes "type-safe" -- (happier now?) -- the macros had to redeclare every member-function with a new inline function. That was not too much trouble with the simple "list" class, but for big ones, that would be tedious. I hadn't been following the discussion here before the last couple of weeks, but my initial impression is that I would probably favor an extension to the language that recognizes the concept of generics. I'm not yet convinced that "templates" will do the job as well as could be wished, but my mind is open. I will take this opportunity to repeat my request: I sure wish someone would be good enough to send me the "summary" article that I've seen allusions to. In fact, any intersting articles on this topic would be appreciated. It is good to know that, "This has all been discussed here at length before," but would actually like to here the arguments that were put forward. My mail address is sun!megatest!djones. Thanks. Dave