Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!mips!daver!tscs!tct!chip From: chip@tct.com (Chip Salzenberg) Newsgroups: comp.lang.c++ Subject: Re: About Lists and things... Message-ID: <2865E7A8.179A@tct.com> Date: 24 Jun 91 12:38:00 GMT References: <285E75EC.37E7@tct.com> <18982@prometheus.megatest.UUCP> Organization: TC Telemanagement, Clearwater, FL Lines: 40 According to djones@megatest.UUCP (Dave Jones): >From article <285E75EC.37E7@tct.com>, by chip@tct.com (Chip Salzenberg): >> According to djones@megatest.UUCP (Dave Jones): >>> while( member = (SomeType*)List_iter_next(&iter)) >> >> This is exactly the downcast hackery that I avoid at all costs. > >And that is exactly the kind of derisive pedantry that I avoid at all >costs. Better pedantic than unsafe. >Even though the above technique has proved perfectly adequate in C-code >for six years, my posting asked for a better way to do it in C++. That technique was never "perfectly adequate," but in C there's little alternative. >Do you have any suggestions, or only insults? My suggestions had been enumerated before. But, to repeat: 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. Use templates. If real templates are unavailable, use the preprocessor. Never, ever create "isa" or "typeof" or "classname" functions for any purpose other than debugging. Any time you would depend on such a function, create a virtual function that does what you really wanted done in the first place. Comments? -- Chip Salzenberg at Teltronics/TCT , "You can call Usenet a democracy if you want to. You can call it a totalitarian dictatorship run by space aliens and the ghost of Elvis. It doesn't matter either way." -- Dave Mack