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