unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: "Maciek Godek" <pstrychuj@gmail.com>
To: "Clinton Ebadi" <clinton@unknownlamer.org>
Cc: guile-user@gnu.org
Subject: Re: SOS: Simple Object System
Date: Wed, 24 Sep 2008 23:04:51 +0200	[thread overview]
Message-ID: <e2ceda030809241404g571eb142g973b957d6704a6b1@mail.gmail.com> (raw)
In-Reply-To: <874p45zanl.fsf@unknownlamer.org>

2008/9/24 Clinton Ebadi <clinton@unknownlamer.org>:
>
>> The other is that in GOOPS a method is something
>> different than what is commonly known in OOP, because
>> a class doesn't know its methods (and furthermore,
>> methods can be created at any time of program execution,
>> not only during class definition). I'm not saying that
>> it's good or bad (but it's quite confusing when a few similar
>> but different notions share one name)
>
> Interestingly enough, CLOS predates C++ and Java ;-)

No wonder -- lambda calculus is a formal system to express concepts
and you can express practically anything in it. C was invented to program
von Neumann machines, and both C++ and Java are derivatives of C.

Note however that both these languages were invented to address
the particular needs of OOP and as such are well suited for that purpose
(or at least that's what the most people think. CLOS is rarely used
compared to C++ and Java -- can you explain why?)

> Separating classes and generic functions makes the language more
> powerful--now two orthogonal concepts may be combined in arbitrary
> ways. The classic example of having generic functions are multimethods
> wherein you can dispatch on the type of every argument of the
> generic. A simple example of this is the (simplified) present method
> from CLIM:
>
>  (define-generic present (instance view))
>
> Which then allows you to do nifty things like:
>
>  (define-method (present (instance <image>) (view <text-view>))
>     (format #t "[~A]" (alt-text-of instance)))
>  (define-method (present (instance <image>) (view <graphical-view>))
>     (display the image somehow))
>
> etc.

And what about
(define-method (present (zone <timezone>) (part-of-year <season>))
(define-method (present (santa <donor>) (child <acceptor>)))
?
I mean of course these examples are artificial, but that's not their point :)
(I won't expose it now to keep the reader in suspense, but stay tuned
as it will certainly appear in the sequel)

> Doing this with a single-dispatch system is much less aesthetically
> pleasing. Note also that multimethods are only one of many advantages
> to having generic functions--they also enable method combinations and
> a few other things. Stylistically, they make the OO system integrate
> cleanly with the rest of the language rather than having its own
> specialized syntax for method invocation.

I see your point, but I can't agree with it -- multimethods certainly
cause ambiguity and make the code harder to read (you can't tell
which method will be called unless you know the types of all its
arguments).

I've got a feeling that CLOS is an attempt to mimic synonymy that
is present (yes, present!) in natural languages. Yet it causes a lot
of confusion!

Note that in C++like syntax, you always precede the name of the
method with the object's name, and therefore you always specify
the context for your expression. (the object is the context)

This resembles the let form known from lisp, that is also used
to build context. (No expression in the world is context-free, but
the multimethods of CLOS seem to deny this simple truth)

>> There is also another issue concerning the fact that
>> methods are available in global namespace -- the
>> performance of the interpreter is always penalized
>> by the type lookup (obviously, this doesn't have to
>> be the case if the code is compiled)
>
> Type lookup in GOOPS should be very fast--there are a few fairly
> simple implementation techniques that more or less eliminate the
> overhead of method dispatch (or at least turn it into a few very low
> overhead table lookups). /The Art of the Metaobject Protocol/ is a
> good inexpensive book that gives a decent overview of how to implement
> a fast CLOS.

I'm not arguing about this -- especially that there's great conceptual
gain that results with this sort of elasticity. (Performance is the last
thing I care about right now. But I hope you're right :>)

>> But the most important feature of OOP that is missed
>> in GOOPS (because of global namespace methods) is the lack
>> of the clean separation of interface and implementation
>> in the way it's done in java, C# and the like.
>
> Actually, CLOS/GOOPS are perhaps the cleanest way to separate
> interface from implementation. You define a protocol as a set of
> generic functions and define methods upon them -- with no concern for
> the actual classes used with the protocol.

The disadvantage is that (unlike in Java, C# etc.) the "interface" isn't an
explicit object. I agree that this can be overcome with a proper discipline
imposed on source code, but the documentation of GOOPS makes me
think that no such discipline has yet been developed.

> In this way you can do implementation sharing via class inheritance or
> something akin to Java interfaces (if I understand them properly; I
> refuse to use such a language) and implement the protocol for
> arbitrary classes without having to arbitrarily force them to inherit
> from unrelated classes.

I don't quite get what you mean (I'd need an example).
BTW Java seems to gain popularity instead of loosing it.
(And I think that stupidity of mankind and human ignorance
are not the only reasons)

I admit that my arguments are somewhat abstract -- I haven't written
anything using GOOPS or CLOS, only read some documentation
(and although my mind was initially tabula rasa, but as I was getting
deeper into that forest, I kept having more and more doubts. Maybe
it's because I knew C++ before GOOPS?)

Best regards
M.




  reply	other threads:[~2008-09-24 21:04 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-13 22:42 SOS: Simple Object System Maciek Godek
2008-09-14 10:22 ` Neil Jerram
2008-09-14 11:21 ` Greg Troxel
2008-09-15  6:48 ` Andy Wingo
2008-09-24 13:09   ` Maciek Godek
2008-09-24 16:14     ` Ludovic Courtès
2008-09-24 18:00     ` Clinton Ebadi
2008-09-24 21:04       ` Maciek Godek [this message]
2008-09-24 22:14         ` David Séverin
2008-09-24 22:38         ` Clinton Ebadi
2008-09-25 23:03           ` Linas Vepstas
2008-09-26 14:20           ` Maciek Godek
2008-09-25 13:58         ` David Séverin
2008-09-25 17:17           ` Maciek Godek
2008-09-24 22:25     ` Jon Wilson
2008-09-24 22:45     ` Jon Wilson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e2ceda030809241404g571eb142g973b957d6704a6b1@mail.gmail.com \
    --to=pstrychuj@gmail.com \
    --cc=clinton@unknownlamer.org \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).