comp.lang.ada
 help / color / mirror / Atom feed
From: James O'Connor <joconnor@jmpstart.com>
To: Robert A Duff <bobduff@world.std.com>
Subject: Re: Cumbersome Polymorphism
Date: 1997/01/25
Date: 1997-01-25T00:00:00+00:00	[thread overview]
Message-ID: <32EAA1A0.7C43@jmpstart.com> (raw)
In-Reply-To: E4KKqz.CJM@world.std.com


Robert A Duff wrote:
> 
> In article <5c9put$48t@hetre.wanadoo.fr>,
> J-P. Rosen <Rosen.Adalog@wanadoo.fr> wrote:
> >Richard Irvine <irv@eurocontrol.fr> wrote:
> >>Before using Ada I used Smalltalk.
> >>A Smalltalk variable can hold an instance of any class.
> >>Of course, this is possible because a Smalltalk variable is just
> >>a pointer to dynamically allocated storage.
> >>The important point though is that the pointers and the problems of
> >>allocation and deallocation are hidden from the Smalltalk programmer,
> >>while the Ada programmer is obliged to be (painfully) aware of them
> >>much of the time.
> 
> The problems of allocation and deallocation are hidden from the
> Smalltalk programmer (and from the Ada programmer, if you can find a
> garbage-collected implementation of Ada, which isn't easy).  But the
> pointers are not hidden in either language: The fundamental thing that
> makes a pointer a pointer is that two pointers can point at the same
> thing.  This is what makes pointers useful.  And this happens in both
> languages, despite the fact that dereferencing the pointer is always
> implicit in Smalltalk.  

That's actually a big difference in approach (IMHO).  While it's true
that pointers are not hidden in Smalltalk, they are also not viewed as
such.  Since every variable is really a pointer and every pointer is
automatically derefrenced, you stop thinking in terms of pointers and
just end up think in terms of the objects they point at.  There is no
'non-pointer' syntax to deal with.


> In Ada, you are forced to use a pointer if you
> have something that changes size, and this is indeed unfortunate from
> the functionality point of view.  In Smalltalk, you are forced to use a
> pointer ALWAYS, and IMHO that's even more unfortunate.

I'm curious, why do you consider that unfortunate?  It certainly makes
the sytanx very clean and alleviates a lot of headaches from
developers.  Like I said, you stop thinking in terms of pointers.

> 
> Note that in Ada, if you have to use a pointer for low-level
> implemenation reasons, like the fact that the thing changes size, you
> can hide this fact from clients.  You can't do that in Smalltalk, if I
> remember correctly, since assignment in Smalltalk is always allowed, and
> always means "copy the pointer" -- there's no simple way of preventing
> the client from evilly making aliases.

How do you evilly (sp?) make an alias?  Sounds like Frankenstein. 
Frankencode? If you have

| a b c| 
a := 'A String'
b := 47.
c := a.
c := 100.


If you evaluate a, it is still 'A String', but C is now 100.  Also there
are some limits on when you can do assignments.  For example, you cannot
directly assign to a method parameter

someMethod: anObject.

	anObject := 5.

Is illegal.
As is trying to directly change an instance variable

changePoint: aPoint

	aPoint x := 100.

As is trying to copy and switch.

changePoint: aPoint.

	myX := aPoint x.
	myX := 100.

The orignal aPoint will remain unchanged.
You still have to honor the public interface of the object you are
dealing with.
If you want to be 'evil' you can use #become: to switch object
identities, but the results of #become: are implementation dependent.
You can also do...

| anObject x |

x := anObject getCollection.
x add: SomeUglyClass new.

But that is considered bad form.  Usually your collections are kept
private and you provide an add: method for them in your own extrenbal
interface in which you can reject bad input.

Even though Smalltalk is dynamically typed and is all pointers.  It's
pretty hard to do something really stupid and pretty easy to protect
against it.  It's not impossible, though.  If you really try you can be
malicious, but then it's your own program that blows up.

> 
> - Bob

-- 
James O'Connor 
--------------------------------------
joconnor@jmpstart.com
http://www.jmpstart.com
--------------------------------------




  reply	other threads:[~1997-01-25  0:00 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-01-23  0:00 Cumbersome Polymorphism Richard Irvine
     [not found] ` <5c9put$48t@hetre.wanadoo.fr>
1997-01-25  0:00   ` James O'Connor
1997-01-25  0:00   ` Robert A Duff
1997-01-25  0:00     ` James O'Connor [this message]
1997-01-26  0:00       ` Brian Rogoff
1997-01-26  0:00       ` Robert Dewar
1997-01-27  0:00   ` Jon S Anthony
1997-01-29  0:00     ` Robert Dewar
1997-01-27  0:00 ` Norman H. Cohen
1997-01-28  0:00   ` Dave Gibson
1997-01-28  0:00   ` Jon S Anthony
1997-01-28  0:00   ` Richard Irvine
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox