Subj : Re: How-to on writing an interpreter? To : comp.programming From : Jon Harrop Date : Sun Jul 24 2005 09:27 pm Flavius Vespasianus wrote: > With OO programming the nodes are completely self-contained. You can can > add and delete node types without having to modify any of the interpreter > other than the parser. > > Much easier than what you suggested. No. OO simply trades one problem for another. Without OO, the switches are "completely self-contained". As you say, the OO approach allows you to add new nodes with only localised code changes. However, the non-OO approach allows you to write new functions which act upon nodes using only localised code changes. If you add functions over nodes more often than you add new node types (often the case) then OO is actually worse. Consequently, problems such as this (e.g. tree data structures) are typically written using variant types and pattern matching rather than OO when both are available. For example, see the Set and Map modules in the OCaml stdlib. -- Dr Jon D Harrop, Flying Frog Consultancy http://www.ffconsultancy.com .