Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Re: Misuses of ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 34 Topic 9585 of 9831
Post > Topic >>

Re: Misuses of RTTI

by brangdon@[EMAIL PROTECTED] (Dave Harris) May 10, 2008 at 06:14 AM

ouferrat@[EMAIL PROTECTED]
 (OuFeRRaT) wrote (abridged):
> I don't understand the sentence:
> "but the usual rule concerning RTTI is more or less the same as with
> goto statements" can anyone explain it?

Goto is a low-level control, and most possible applications of it are
better represented with higher level constructs such as for, while,
switch etc. Writing shorter functions helps.

The author is saying that RTTI (presumably meaning typeof and
dynamic_cast<>) is also low-level, and most possible applications of it
are better represented with higher level constructions such as virtual
functions, interfaces/multiple inheritance, the Visitor type-discovery
pattern, and so forth. Sometimes we can use templates or other mechanisms
to avoid losing track of the exact type in the first place, making RTTI
redundant.

I broadly agree. However, one difference is that goto is a local
construct, within a single function, and we can rewrite the function to
not use it without affecting anything else. Where-as getting rid of RTTI
often means revising the architecture across many different cl*****.
Getting it right first time often requires careful design and foresight.
If some of the code is not under our control, then the ideal design may
not be possible, and even if all the code is under our control, an
RTTI-less design may mean more coupling, or rather more lack of locality,
than we want. Eg we may not want to inflict the burden of sup****ting a
particular virtual function, or the Visitor pattern, on every class in a
hierarchy.

So this local versus non-local issue makes it not a perfect analogy, and
in practice I find I use RTTI far more often than goto. However, the
author's point remains. Goto and RTTI are not the tools to keep at the
very top of your toolbox. Try the alternatives first.

-- Dave Harris, Nottingham, UK.

-- 
      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 34 Posts in Topic:
Misuses of RTTI
OuFeRRaT <ouferrat@[EM  2008-05-09 21:13:35 
Re: Misuses of RTTI
Pavel Minaev <int19h@[  2008-05-10 05:52:08 
Re: Misuses of RTTI
Mathias Gaunard <loufo  2008-05-10 05:53:41 
Re: Misuses of RTTI
brangdon@[EMAIL PROTECTED  2008-05-10 06:14:41 
Re: Misuses of RTTI
Francis Glassborow <fr  2008-05-10 06:14:40 
Re: Misuses of RTTI
MiB <Michael.Boehnisch  2008-05-10 14:08:42 
Re: Misuses of RTTI
"Bo Persson" &l  2008-05-11 16:40:58 
Re: Misuses of RTTI
Carl Barron <cbarron41  2008-05-11 22:13:29 
Re: Misuses of RTTI
=?UTF-8?B?RXJpayBXaWtzdHL  2008-05-13 10:55:29 
Re: Misuses of RTTI
galathaea <galathaea@[  2008-05-13 21:12:13 
Re: Misuses of RTTI
Gerhard Fiedler <gelis  2008-05-13 21:27:28 
Re: Misuses of RTTI
bravo <szymon.gatner@[  2008-05-14 08:36:57 
Re: Misuses of RTTI
brangdon@[EMAIL PROTECTED  2008-05-17 02:27:45 
Re: Misuses of RTTI
Tony Delroy <tony_in_d  2008-05-14 08:38:14 
Re: Misuses of RTTI
Mathias Gaunard <loufo  2008-05-14 12:27:28 
Re: Misuses of RTTI
Mathias Gaunard <loufo  2008-05-14 12:55:43 
Re: Misuses of RTTI
anthonypon@[EMAIL PROTECT  2008-05-15 02:47:07 
Re: Misuses of RTTI
Greg Herlihy <greghe@[  2008-05-15 11:21:05 
Re: Misuses of RTTI
dizzy <dizzy@[EMAIL PR  2008-05-15 11:57:29 
Re: Misuses of RTTI
dizzy <dizzy@[EMAIL PR  2008-05-15 11:57:29 
Re: Misuses of RTTI
Edward Diener <diener8  2008-05-15 15:57:15 
Re: Misuses of RTTI
Mathias Gaunard <loufo  2008-05-16 17:30:34 
Re: Misuses of RTTI
Frank Birbacher <blood  2008-05-16 17:44:13 
Re: Misuses of RTTI
Daniel James <wastebas  2008-05-16 17:43:20 
Re: Misuses of RTTI
"Marcin Kalicinski&q  2008-05-17 02:57:29 
Re: Misuses of RTTI
Edward Diener <diener8  2008-05-17 14:38:55 
Re: Misuses of RTTI
Greg Herlihy <greghe@[  2008-05-17 14:36:47 
Re: Misuses of RTTI
Edward Diener <diener8  2008-05-17 14:39:16 
Re: Misuses of RTTI
Andre Kaufmann <akfmne  2008-05-17 14:38:10 
Re: Misuses of RTTI
Andre Kaufmann <akfmne  2008-05-17 23:20:59 
Re: Misuses of RTTI
Daniel James <wastebas  2008-05-18 16:48:55 
Re: Misuses of RTTI
Andre Kaufmann <akfmne  2008-05-19 06:05:40 
Re: Misuses of RTTI
Francis Glassborow <fr  2008-05-19 12:01:47 
Re: Misuses of RTTI
Francis Glassborow <fr  2008-05-20 18:59:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 21:50:07 CDT 2008.