comp.lang.ada
 help / color / mirror / Atom feed
From: stephen@dino.dnsalias.com (Stephen J. Bevan)
Subject: Re: OOD in Ada?
Date: Fri, 05 Jul 2002 20:02:06 GMT
Date: 2002-07-05T20:02:06+00:00	[thread overview]
Message-ID: <m3fzyyc5aa.fsf@dino.dnsalias.com> (raw)
In-Reply-To: 3d1870b0$0$8507$cc9e4d1f@news.dial.pipex.com

"David Crocker" <dcrocker@eschertech.com> writes:
> Let me give you and others who have replied to my posting a real example of
> an OO system where the "withing" problem occurs and I can't see an easy way
> out of it.
> 
> A compiler is being written. The compiler has to know about objects of class
> Expression and Statement. Each of these is actually an abstract class with
> many descendents (because there are many types of expression etc.).

There seems to be two schools of thought about how best to structure a
compiler :-

* The "OO" way in which a base class is defined for various syntactic
  elements such as Expression and Statement and then subclasses are
  defined for specific instances such as IfStatement, ... etc.

* The "old" way by defining a record for any syntactic units of
  interest and use case to cover variants.

The "OO" way has an advantage if your implementation strategy is fixed
but the language is changing since you can add new nodes without
disturbing other code: just subtype and implement the required
methods.

The "old" way has an advantage if your language is fixed but your
implementation strategy is not i.e. you may start out with some
strategy and then realise that an extra pass could be used to do some
othe sort of analysis/optimisation.  That's because you can add a new
phase without having to touch the nodes or the other phases (just the
code where you plug the new phase in).

From your example it isn't clear to me which situation you are in,
though statistically I would guess you have a fixed language.  In that
case I'd just stick with the "old" way of doing things and avoid
classes completely.  Some recommend sticking with the "OO" style but
using some flavour of visitor to avoid having to touch so many classes
should a new phase need to be added.  However, it isn't clear to me
how this is an improvement over the "old" way of doing things.

This is probably not the answer you are looking for but it is how I'd
solve your problem.



  parent reply	other threads:[~2002-07-05 20:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-21 16:39 OOD in Ada? David Crocker
2002-06-21 17:20 ` Pat Rogers
2002-06-21 19:37   ` Ed Falis
2002-06-23  3:05   ` Ted Dennison
2002-06-23  7:03     ` tmoran
2002-06-24 21:41       ` Ted Dennison
2002-06-24 14:19     ` Stephen Leake
2002-06-21 17:22 ` Marin David Condic
2002-06-22  4:42 ` Jeffrey Carter
2002-06-22  9:18 ` Dr. Michael Paus
2002-06-22  9:47   ` Pascal Obry
2002-06-22 13:11     ` Dr. Michael Paus
2002-06-22 13:46       ` OOD in Ada? Correction Dr. Michael Paus
2002-06-22 18:21         ` Simon Wright
2002-06-28 23:57         ` Randy Brukardt
2002-07-09  8:45           ` Preben Randhol
2002-07-09 17:12             ` Mark Biggar
2002-07-09 19:40             ` Randy Brukardt
2002-06-23  3:33   ` OOD in Ada? steve_H
2002-06-23  4:55     ` Jim Rogers
2002-06-23  5:33       ` achrist
2002-06-25 18:00       ` Georg Bauhaus
2002-06-25 18:55         ` Marin David Condic
2002-07-07 18:19           ` Daniel Dudley
2002-06-23  7:46     ` Dr. Michael Paus
2002-06-24  5:06       ` steve_H
2002-06-23 19:26   ` Chad R. Meiners
2002-06-22 22:47 ` Dmitry A.Kazakov
2002-06-24 20:03 ` Kevin Cline
2002-06-25 13:32   ` David Crocker
2002-06-25 13:58     ` Marin David Condic
2002-06-26 18:16       ` tmoran
2002-06-26 18:47         ` Marin David Condic
2002-06-27 18:23           ` tmoran
2002-06-28 13:09             ` Marin David Condic
2002-06-26  0:59     ` Hyman Rosen
2002-06-26  4:57       ` Jim Rogers
2002-06-26 12:49       ` Marin David Condic
2002-06-26  9:01     ` Fraser Wilson
2002-06-29  0:08       ` Randy Brukardt
2002-07-01 11:50         ` Fraser Wilson
2002-07-05 20:02     ` Stephen J. Bevan [this message]
2002-07-09 19:19 ` Craig Carey
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox