[self-interest] Re: data structures

David Ungar David.Ungar at Eng.Sun.COM
Wed Jun 9 19:55:03 UTC 1999


Amen!

When designing Self
I came to believe (and still do) that the idea of 'nil' is not 
object-oriented at all.
It is just a holdover from Lisp via Smalltalk.
If I had to do it all over again, there would be no nil in Self.

(So why? Because 'nil' is the same no matter what kind of object
isn't there. This leads to code such as:

nil = foo ifFalse: [
    <do something with foo>
]


If instead, you make a special object that respects the right 
protocol you could write

foo doSomething

or

foo doSomethingIfNotInitialized: [...]

- Dave


PS: I'm not sure my messages are reaching the alias--could someone verify?


At 3:48 AM -0300 6/9/99, Jecel Assumpcao Jr wrote:
>Ian Trudel wrote:
>> : In Smalltalk we would do "vector new: 3" since everything is
>> : initialized with nil, but Self doesn't like defaults and so you
>> : have to choose some initial value (like 0 in this example)
>> : explicitly.
>>
>> Out of interest, why Self doesn't like defaults? Time consuming? Personnaly,
>> I prefer everything has a default value before uses. Maybe just because I
>> am, and every programmer I know, are human and sometimes forgot to
>> initialize.
>
>Self is based on prototypes instead of classes. A class includes,
>among many other things, a plan to build object instances of itself.
>This plan (the #new method in Smalltalk, the constructor in other
>languages) will normally replace any defaults that the system uses
>when allocating the instance with values that are appropriate for
>that class.
>
>A prototype, on the other hand, is usually "hand made". It can be
>cloned to generate new "instances", but it is an actual working
>"instance" itself and its slot values should reflect this. We could
>have a Record class in Smalltalk with this creation method:
>
>   new
>   "creates an initialized Record object"
>   ^ self basicNew initialize
>
>where the instance method is:
>
>   initialize
>   "sets the initial values for the Record object"
>   name := 'unnamed'.
>   age := 0.
>   ^ self
>
>We could do the exact same thing in Self, of course:
>
>   (| parent* = traits clonable.
>      name.
>      age.
>      copy = ("creates a new initialized record"
>              resend.copy initialize).
>      initialize = ("sets the initial values"
>                    name: 'unnamed'.
>                    age: 0.
>                    self)
>   |)
>
>but a the following would be much more Selfish:
>
>   (| parent* = traits clonable.
>      name <- 'unnamed'.
>      age <- 0
>   |)
>
>In the first Self example, the slot values for the prototype are
>the default (nil). They are a string and an integer for every
>object clones from the prototype, however, so the prototype is not
>a true representative of this kind of object. The second example
>fixes this, but is now subject to the "prototype corruption
>problem". That is when you change the prototype itself instead of
>a copy (by sending it the message 'age: 10', for example). This
>will effect every new clone created in the future.
>
>So what I should have said in my comment what that in Self we should
>always avoid depending on defaults like nil but should instead create
>the prototypes with the right types of values (which are another kind
>of defaults, of course).
>
>-- Jecel
>
>
>------------------------------------------------------------------------
>Explore the Web for sites in Science & Technology from Looksmart!
>http://clickhere.egroups.com/click/302
>
>
>eGroups.com home: http://www.egroups.com/group/self-interest
>http://www.egroups.com - Simplifying group communications

 

     David Ungar
     Sun Microsystems Laboratories
     (650) 336-2618

------------------------------------------------------------------------

eGroups.com home: http://www.egroups.com/group/self-interest
http://www.egroups.com - Simplifying group communications






More information about the Self-interest mailing list