Eliminating assignments and variable syntax (accessors)
Stefan Matthias Aust
sma at netsurf.de
Tue Aug 3 22:06:25 UTC 1999
>> From: Stefan Matthias Aust <sma at netsurf.de>
>> The problem IMHO is that now "self a: b" and "a: b" doesn't mean
>> the same.
>Well, the problem is the same as for a:=b. 'a' can be either an
>instance variable or a local variable. I am not saying this is good
>or bad, it's just the same is it is now.
I should have written earlier that my emails weren't meant as critique.
Please don't feel offended. I'm still unsure what solution I'd prefer, so
I fired in all directions :-) You're right, with both ways, you've to
carefully watch the temporary declaration to understand the meaning. I
think - no I know - I dislike this.
>> I don't care [about implementation]
>Funny, that was *exactly* the idea of my proposal.
I'm afraid I wasn't specific enough. I want to distinguish slot access and
message sends. So my argument was not to show the fact that slot access is
just another special case of method calls. From my experience, this
distinction will help people to learn the language.
I know this isn't Smalltalk anymore but I don't care at this moment: The
dot-operator is well known to access slots, so why not write "self.x" to
access slot x of the current receiver or "anyObject.y" to access
anyObject's slot. The :=-operator is well known for assignments, so use it
to assign values to slots or local variables. The -operator is known for
indexed access, so use it instead of at: and at:put:. Actually all
operators can be understood as macros.
>Well, I guess that is the part that got sort of lost in the noise:
>If there are no accessors, the compiler compiles 'accessor/mutator'
>message sends to self as direct variable access. Therefore, the
>object itself can access its own instance variables (and local
>variables) even if the accessors are not defined, whereas in SELF
>there is an automatic definition of accessors.
Thinking about both alternatives, I think I'd prefer the explicit
definition of accessors. Better tools - as already suggested - is probably
the best way. Instead of adding space-separated identifiers to the
....instVarNames:... method call, the browser should generate slot and
....especially if you want to implement something like lazy initialization
without workarounds like
self basic_slot ifNil: [self basic_slot: self compute_slot].
self basic_slot: object
where you have to call your slot "basic_slot" even if everybody else should
know it as slot.
Stefan Matthias Aust // Bevor wir fallen, fallen wir lieber auf.
More information about the Squeak-dev