caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benjamin Geer <ben@socialtools.net>
To: Jacques Garrigue <garrigue@kurims.kyoto-u.ac.jp>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] does class polymorphism need to be so complicated?
Date: Thu, 21 Aug 2003 10:19:46 +0100	[thread overview]
Message-ID: <3F448EB2.9020103@socialtools.net> (raw)
In-Reply-To: <20030821102946Y.garrigue@kurims.kyoto-u.ac.jp>

Jacques Garrigue wrote:
> Even for object arguments, not all classes make sense when extended.

The problem is that it is often difficult to know, at the outset, 
whether it makes sense for a class to be extended.  Sometimes you start 
out with a concrete class, thinking 'no one will ever want to extend 
this', and later you realise that it should have been an interface, 
because there's a real need for different implementations.  It's easier 
to change a class into an interface if all methods that use the class 
don't also have to change, i.e. if the syntax for using an interface is 
the same as the syntax for using a class.

Another approach is to use interfaces for everything.  But then you 
really need a lightweight syntax for handling interfaces in methods.

> So we are back to an often fairly small number of methods (in my
> experience one or two by big class, but it may depend heavily on your
> design)

See my last message, about writing and using libraries.

> Another approach which was not described yet, and which I use in
> lablgtk for instance, is to add a coercion method to classes which form
> the top of a hierarchy. [...]

I agree that this is a slight improvement; it's basically a shorter 
coercion syntax.  Why did you decide to use this approach in lablgtk, 
instead of the other approach you suggested (using virtual methods that 
accept class types)?

> This all depends of the number of methods taking printable as
> argument.  If there are only a few of them, wrapping functions or
> polymorphic methods are probably a good idea. If there are lots of
 > them, then adding such a coercion method may make your design clearer.

It's often difficult to know, at the outset, how many methods will 
ultimately use any given class, particularly if you're writing a 
library.  Perhaps initially there will only be a few, and later on there 
will be many.  Object-oriented programming should mean that you don't 
have to know or care.

The point about clarity is interesting, though; you seem to be saying 
that coercions make code clearer.  While this may be true, the whole 
philosophy of ML seems to be about giving the programmer a choice: type 
specifications are necessary only when there is ambiguity, and are 
optional elsewhere.  Since there is no possible ambiguity in the case 
we're talking about, wouldn't you rather have the choice?  This is why 
the approach using 'open rows' seems more appealing to me.

> And if you're going to change the requirements of a method in the
> middle of your development, this means that there was something wrong
> in your design.

Unfortunately, as hard as we may try to create the perfect design, 
designs always change over time.  I think programming languages should 
try to make those changes as painless as possible.

Ben

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  reply	other threads:[~2003-08-21  9:23 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-08-20 15:42 Benjamin Geer
2003-08-20 16:05 ` Brian Hurt
2003-08-20 16:19   ` Richard Jones
2003-08-20 16:25   ` Benjamin Geer
2003-08-20 17:09     ` brogoff
2003-08-20 17:25       ` Jacques Carette
2003-08-20 23:34         ` Jacques Garrigue
2003-08-21 13:27           ` Jacques Carette
2003-08-20 18:19       ` Benjamin Geer
2003-08-20 20:39         ` brogoff
2003-08-20 21:04           ` Benjamin Geer
2003-08-21  0:28             ` Jacques Garrigue
2003-08-21  8:17               ` Benjamin Geer
2003-08-21  8:58                 ` Jacques Garrigue
2003-08-21  9:38                   ` Benjamin Geer
2003-08-21 11:44                     ` Remi Vanicat
2003-08-21 13:11                       ` Richard Jones
2003-08-21 16:41                         ` Remi Vanicat
2003-08-21 18:04                     ` brogoff
2003-08-21 20:20                       ` Benjamin Geer
2003-08-21 23:35                         ` Benjamin Geer
2003-08-22  3:59                           ` Jacques Garrigue
2003-08-22  7:12                             ` Benjamin Geer
2003-08-21 13:38                   ` Benjamin Geer
2003-08-21  0:58             ` brogoff
2003-08-20 23:40           ` Benjamin Geer
2003-08-21  1:29             ` Jacques Garrigue
2003-08-21  9:19               ` Benjamin Geer [this message]
2003-08-21 18:44               ` Chris Clearwater
2003-08-20 20:43   ` Issac Trotts

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

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

  git send-email \
    --in-reply-to=3F448EB2.9020103@socialtools.net \
    --to=ben@socialtools.net \
    --cc=caml-list@inria.fr \
    --cc=garrigue@kurims.kyoto-u.ac.jp \
    /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 NNTP newsgroup(s).