[comp.lang.eiffel] Request for your favorite OOP idea for possible implementation!

cszthomas@qut.edu.au (05/24/89)

Hi there,

	I am currently involved in some research into adding OOP
extensions to modern modular languages.  I would value any pertinent
ideas or theories that anyone might have as to the best manner of
doing this and exactly what should be implemented (eg. multiple
inheritance/single inheritance, etc.)

	If you have an idea that you just want to throw at me then
EMAIL it to me.  On the other hand if you think it would make a 
good discussion topic by all means post it to the relevant area.
If you do EMAIL anything to me I can't guarantee that I'll be able
to reply, our mail system is particularily user hostile and won't
let me mail out to sites it doesn't know about.

	Thanks in advance.


@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@
{ Richard Thomas  aka. The AppleByter                            }
{   "42" - Douglas Adams                                         }
{                                                                }
{ ACSNet:   richard@qitfit.qitcs.oz                              }
{ InterNet: CSZTHOMAS@QUT.EDU.AU                                 }
{ JANET:    CSZTHOMAS@AU.EDU.QUT                                 }
{ BITNET:   CSZTHOMAS%AU.EDU.QUT@EAN.AC.UK                       }
{ ARPANet:  as previous@UKACRL.BITNET                            }
{ PSI:      PSI%505272223015::CSZTHOMAS                          }
{ Voice:    (07) 394-3861                                        }
{ Snail:    3/11 Haig St.                                        }
{	    Coorparoo, QLD  4151                                 }
@~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~@

marcap@concour.CS.Concordia.CA (Marc Pawlowsky) (05/30/89)

In article <3720@qut.edu.au> cszthomas@qut.edu.au writes:
>	I am currently involved in some research into adding OOP
>extensions to modern modular languages.  I would value any pertinent
>ideas or theories that anyone might have as to the best manner of
>doing this and exactly what should be implemented (eg. multiple
>inheritance/single inheritance, etc.)

My pet peeves are:

1) := is inconsistent.  In both eiffel and Smalltalk := when applied
   to a primitive (integer, real, character, ...) automatically
   creates a new object, with the same value.  Yet when := is used
   for a class it creates a reference to the same object.  It would
   be nice if this inconsistency was cleared up, by having := always
   refer to the same object and not create a new one.

2) There is no true clone, deepCopy methods in either language.  By this
   I mean a method that recursively returns a new object, with all the
   instances variables also cloned (deepCopy).  This is often needed.  While
   it is possible to create such a method, I think it should be part of the
   language definition.

   A simple operator should be used (e.g. <-, or :-).

bertrand@eiffel.UUCP (Bertrand Meyer) (06/01/89)

From <859@clyde.Concordia.CA>, marcap@concour.CS.Concordia.CA (Marc Pawlowsky):
 
> 1) := is inconsistent.  In both Eiffel and Smalltalk := when applied
> to a primitive (integer, real, character, ...) automatically
> creates a new object, with the same value.  Yet when := is used
> for a class it creates a reference to the same object.  It would
> be nice if this inconsistency was cleared up, by having := always
> refer to the same object and not create a new one.

	What is important is to have an operation that always has the
same semantics. In Eiffel this is called Clone and has the same
semantics for simple values and class types. (Sometimes, rather than
Clone, one may wish to use copy, introduced by version 2.2, which is
the same as Clone except that no new allocation is entailed.)

	Contrary to what Mr. Pawlowsky seems to imply, an operation
which has dual semantics, such as := in Eiffel (copy for simple
values, reference for objects), is indeed useful. For example in most
cases it provides what one wants as semantics for ``assignment to an
element of an array'':  a.enter (i, x) in Eiffel. If x is an integer,
you want it to be copied to entry i of a; if it is a reference, you
don't want the object to be copied. There are exceptions, of course,
but this seems to be the general case.

	Given that we have both an operation which ensures copy
semantics and one which ensures dual semantics, the question
remains of whether it was a good idea to use the simpler symbol (:=)
for the latter, reserving a more cumbersome one (Clone) for the
former.  I believe the right choice was made in Eiffel. If computer
programming started in 1989 the answer might be different but given
that hundreds of thousands of current programmers (and hence future
Eiffel programmers) are used to a certain meaning for :=, reversing
this meaning would have been irresponsible, potentially leading to
massive errors in software produced in years to come.

> 2) There is no true clone, deepCopy methods in either language.  By this
> I mean a method that recursively returns a new object, with all the
> instances variables also cloned (deepCopy).  This is often needed.  While
> it is possible to create such a method, I think it should be part of the
> language definition.

	Eiffel version 2.2 has a deep copy and a deep equal operation,
defined not as language primitives but as features in the
library class ANY, inherited by everyone. (By the way, a forthcoming
message will give the precise list of everything new in 2.2.)

>    A simple operator should be used (e.g. <-, or :-).

	This is purely a syntactical question. Because deep copy and
deep equal may be defined as normal features in a library
class, we felt there was there is no need to invent yet another special
notation.  In Eiffel, writing

	a.deep_copy (b)

seems highly preferable (more clear to both a newcomer and an
experienced programmer, easier to remember etc.) to something like a :-
b.  In fact, I believe the latter to be quite dangerous because of its
similarity to a := b, which has a drastically different semantics.
(See also section 5.8.3 in my book ``Object-Oriented Software
Construction''.)
-- 

-- Bertrand Meyer
bertrand@eiffel.com