home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / modula2 / 1565 < prev    next >
Encoding:
Internet Message Format  |  1992-12-14  |  1.6 KB

  1. Path: sparky!uunet!mcsun!uknet!mucs!m1!bevan
  2. From: bevan@cs.man.ac.uk (Stephen J Bevan)
  3. Newsgroups: comp.lang.modula2
  4. Subject: Re: GENERIC TYPE IN MODULA-2
  5. Message-ID: <BEVAN.92Dec14205314@hippo.cs.man.ac.uk>
  6. Date: 14 Dec 92 20:53:14 GMT
  7. References: <00964E42.F315D220.13757@esseX.stfx.ca>
  8. Sender: news@cs.man.ac.uk
  9. Organization: Department of Computer Science, University of Manchester
  10. Lines: 30
  11. In-reply-to: andrea@ESSEX.STFX.CA's message of 10 Dec 92 21:39:54 GMT
  12.  
  13. In article <00964E42.F315D220.13757@esseX.stfx.ca> andrea@ESSEX.STFX.CA (John Andrea) writes:
  14.  
  15.    TYPE
  16.       data :ADDRESS;
  17.       left, right :Pointer;
  18.  
  19.    Unfortunately that approach removes type checking and you can put the wrong
  20.    data type into your tree.
  21.  
  22. Not if you create a separate module where the parameters have the
  23. correct type and must be coerced to the above.  Granted you could get
  24. this wrong, but if you do it once, you can use it as a template and
  25. then just use search/replace to create a new module with the correct
  26. type.  If the compiler is any good, it should be able to inline all
  27. the interface procedures and so it doesn't cost you anything at
  28. runtime.
  29.  
  30.  
  31.    Yes it looks like the OO approach wins in a situation like this.
  32.  
  33. The one OO solution I've seen to this is not one I'd advocate and not
  34. one I think comp.object readers would like either.  The classic (and
  35. IMHO still the best) solution to this problem is parametric
  36. polymorphism aka ``generics'' in Ada or ``templates'' in C++ (the
  37. above solution is just a manual instantiation method).  This has
  38. _nothing_ to do with OO.
  39.  
  40. yours against gratuitous use of OO as a panacea,
  41.  
  42. bevan
  43.