[squeak-dev] Class with nil environment?!

Frank Shearar frank.shearar at gmail.com
Thu Jul 11 09:08:20 UTC 2013


On 11 July 2013 01:01, David T. Lewis <lewis at mail.msen.com> wrote:
> On Wed, Jul 10, 2013 at 06:50:09PM -0400, Bob Arning wrote:
>>
>> On 7/10/13 5:59 PM, Frank Shearar wrote:
>> >Well, with my nil-hating hat on, I'd say that Class >> #environment is
>> >also busted. There's no value in having environment = nil.
>
> Well ok but ... this isn't Java you know, so you don't need to hate
> a perfectly respectable object just because it happens to represent
> nothingness  ;-)

Class >> environment
    environment = #deferToSuperclass ifTrue: [ ^ super environment ].
    ^ environment

would still give the whatever-my-superclass-does while also clearly
indicating that noone accidentally forgot to initialise the instvar.
Not a nil in sight!

>> It allows subclasses to track the superclass environment. You can change
>> the environment for a class and all subclasses that have not explicitly
>> declared an environment will share it. Subclasses that have had an
>> explicit environment set will keep that that even when the superclass
>> changes.

Fair enough. That suggests to me that Class >> #declare: _must_ use
`self environment` rather than access the instvar directly. I'm more
than happy to make the change, once we hear back from Colin. (Nudge.)

>> >You're not
>> >saving any space, for instance. What you _do_ have is a piece of
>> >uninitialised state, waiting for someone to reference the instvar
>> >directly (as Class >> #declare: does) and fail with an MNU on nil.
>> >
>> >I'm waiting to hear what Colin has to say, but I'd say that Class >>
>> >#declare: has every reason to assume that an instvar's initialised,
>> >and that #environment should simply say "^ environment".
>>
>> The counter-argument, of course, is to use the accessors and not tinker
>> directly with the instvars unless you are sure you know what you are doing.
>
> That sounds like good advice to me.
>
> And I agree with Frank that we should hear what Colin has to say about it.
>
> Dave

frank


More information about the Squeak-dev mailing list