home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11491 < prev    next >
Encoding:
Text File  |  1992-07-25  |  3.2 KB  |  68 lines

  1. Newsgroups: comp.lang.c++
  2. From: nikki@trmphrst.demon.co.uk (Nikki Locke)
  3. Path: sparky!uunet!pipex!demon!trmphrst.demon.co.uk!nikki
  4. Subject: Re: Covariant Types in Derived Classes
  5. Distribution: world
  6. References: <VKE52M@netmbx.netmbx.de>
  7. Organization: Trumphurst Ltd.
  8. Lines: 55
  9. Date: Fri, 24 Jul 1992 19:22:08 +0000
  10. Message-ID: <712030928snx@trmphrst.demon.co.uk>
  11. Sender: usenet@gate.demon.co.uk
  12.  
  13. I am one of those who view RTTI with suspicion. I have no objection to its 
  14. inclusion in the language, but I hope it doesn't encourage a rash of 
  15. Smalltalk programming, or the absolutely horrible switch(typeof(thing)) !
  16.  
  17. In article <VKE52M@netmbx.netmbx.de> jrobie@netmbx.netmbx.de (Jonathan Robie) writes:
  18.  
  19. > maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  20. > >>If I want a generic print function that can handle all types as though they
  21. > >>were basic types, then this print function must know the location and type
  22. > >>of each member, and also the name if the function is to be particularly
  23. > >>useful.
  24. > >    Such a utility function would be useful for debugging only.
  25. > >Yes, to do it you would need RTTI.
  26. > Not so.  A report generator might start by showing me the default
  27. > printout for an object.  I can grab fields with my mouse and move
  28. > them around or delete them.
  29. > A user interface tool might allow me to do something similar by providing
  30. > me with a default, editable window.
  31. The report generator and the user interface tool does not _require_ RTTI. 
  32. The objects to be displayed/reported on should return a Collection of field 
  33. specifiers from a virtual function. These field specifiers can then be 
  34. placed on a menu for user selection and placement. The field specifier 
  35. will contain virtual functions to format, display, validate and set the 
  36. value of each field. A generic user interface object can then be 
  37. constructed to use these methods for displaying and/or editing the field.
  38.  
  39. In any case, how does RTTI help ? You have a tool which will allow the 
  40. user to create an input screen for any arbitrary object. How will knowing 
  41. the class of the object to be displayed help ? What you really need to 
  42. know is how to display/edit each property of an object of that class.
  43.  
  44. A debugger does, of course, require RTTI. At least one C++ debugger 
  45. actually uses RTTI info placed in the executable by the compiler to 
  46. identify the dynamic type of objects. However, this information IS NOT 
  47. ACCESSABLE TO THE PROGRAMMER.
  48.  
  49. The only use I can see for RTTI is downcasting. The only places where I 
  50. have found it expedient to do downcasting are in efficient implementations
  51. of Collection templates. I also feel very uncomfortable about it, as I 
  52. know my Collections are not really safe - I should fix this by making my 
  53. base collection class publicly read-only (by making all the non-const 
  54. members protected), but I haven't yet.
  55.  
  56. I haven't properly got to grips with mixins yet, but I have a glimmer of 
  57. understanding that suggests that they might be used to solve many of the 
  58. other problems which tempt you to use downcasting.
  59. ---
  60. Nikki Locke              |                        | nikki@trmphrst.demon.co.uk
  61. Trumphurst Ltd.          | Tel: +44 (0)691-670318 | nikki@cix.compulink.co.uk
  62. PC and Unix consultancy  | Fax: +44 (0)691-670316 | nikki@kewill.co.uk
  63.