Re: Looking for a nail

From: Markus Mottl (mottl@miss.wu-wien.ac.at)
Date: Fri Jan 29 1999 - 01:25:16 MET


From: Markus Mottl <mottl@miss.wu-wien.ac.at>
Message-Id: <199901290025.BAA22513@miss.wu-wien.ac.at>
Subject: Re: Looking for a nail
To: dsyme@microsoft.com (Don Syme)
Date: Fri, 29 Jan 1999 01:25:16 +0100 (MET)
In-Reply-To: <39ADCF833E74D111A2D700805F1951EF0F00B93A@RED-MSG-06> from "Don Syme" at Jan 28, 99 05:32:58 am

> Yes, I'd be interested to see a really convincing use of the utility of the
> OO features, e.g. a program or library which is manifestly shorter, cleaner
> and/or simpler when expressed with OO rather than the core features. I
> guess people can take this as a challenge if they like :-) I'm open to be
> convinced - but I'm not convinced yet.

Imagine that all basic types were classes and all of them would support
a method e.g. "print". Than you could do the following:

  let print x = x # print
  List.iter print [3; "hello"; 3.14; ["yeah, another list!"]]

or you want to map various objects to strings:

  let to_string x = x # to_string
  List.map to_string [some_object; another_object; 7; 2.7172]

Some (general) complex stuff you can do with OO (send some messages to
all objects in a container - they do not necessarily have to be members
of the same class, they only share parts of interfaces):

  ASet.iter (fun x -> x#simplify; x#factorize; x#calculate_question 42) s

If you want, I show you a zillion similar constructs, which IMHO make
life *significantly* more comfortable...

I already use this where I can, but if basic types were classes, the first
two examples would also work. There is probably hardly any program, where
you wouldn't need such constructs. Although modules are a great means of
abstraction, show me how you can do such (very readable) things with them.

When I began using the OO features, I rewrote some program to use classes
instead of (algebraic) types. The code not only became much more readable,
but it is much easier to maintain - adding new features takes (in my
experience) far less time.

Best regards,
Markus

-- 
Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl



This archive was generated by hypermail 2b29 : Sun Jan 02 2000 - 11:58:19 MET