[plt-scheme] Object system vs. closures

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Mar 11 10:17:07 EDT 2008

Let me rephrase these answers. Suppose you are willing to use macros  
to define your class/object systems via closures:

1. You should design macros that provide reasonable error messages  
when you send an unknown message to an object, when initialization  
issues go wrong, and probably a few more things.

2. With 1 but a HUGE issue in practice, you should design your object  
system so that the closures are hidden and disjoint from real  
closures. Otherwise someone (you older, some non-oo pieces of your  
large system) may end up treating your objects as closures and just  
invoke them. After you are through with issue 3, this won't be pretty.

3. You should design macros that pre-compute object dispatch so that  
you don't get hit by the sequential search that a cond implies. Since  
method dispatch is the most central operation in OOP, you want at  
least amortized constant time. See Dan Friedman's lecture on object  
passing style or something like that. Or read the paper that Robby  
suggested and the code that goes with it (class.ss).

If you want something real, you are really rewriting (lib class.ss)  
aka scheme/class in a way so that it runs on the syntax systems of  
other Scheme implementations though 2 remains an issue there.

So your question boils down to the trade off between your own effort  
of reconstructing enough of scheme/class -- because real OOP  
programming needs it -- and 'buying into' a multi-manyear effort of  
designing a class system and making it robust (see 1 2 3).

-- Matthias

On Mar 11, 2008, at 8:42 AM, Robby Findler wrote:

> That, performance issues, and the fact that class.ss will have a
> different set of features is probably everything. See
> http://people.cs.uchicago.edu/~robby/pubs/papers/aplas2006-fff.pdf for
> a description of the mzscheme class system that might help you decide.
> Robby
> On Tue, Mar 11, 2008 at 5:04 AM, Dave Griffiths <dave at pawfal.org>  
> wrote:
>>> I'm wondering: what are the advantages and disadvantages of using  
>>> the
>>> mzScheme object system instead of using closures to support OO?
>>> One of the disadvantages is portability I guess?
>>  Meaningful error messages and better readability - I was playing  
>> with
>>  closures for a bit but switched to class.ss.
>>  cheers,
>>  dave
>>  _________________________________________________
>>   For list-related administrative tasks:
>>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme

Posted on the users mailing list.