From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,924aad49bcf9e4e7 X-Google-Attributes: gid103376,public From: James O'Connor Subject: Re: Cumbersome Polymorphism Date: 1997/01/25 Message-ID: <32EAA1A0.7C43@jmpstart.com>#1/1 X-Deja-AN: 212228715 references: <32E7ABE8.3BF3@eurocontrol.fr> <5c9put$48t@hetre.wanadoo.fr> to: Robert A Duff content-type: text/plain; charset=us-ascii organization: JumpStart Systems mime-version: 1.0 reply-to: joconnor@jmpstart.com newsgroups: comp.lang.ada x-mailer: Mozilla 3.01Gold (Win95; I) Date: 1997-01-25T00:00:00+00:00 List-Id: Robert A Duff wrote: > > In article <5c9put$48t@hetre.wanadoo.fr>, > J-P. Rosen wrote: > >Richard Irvine 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 --------------------------------------