[squeak-dev] Class with nil environment?!

tim Rowledge tim at rowledge.org
Thu Jul 11 17:07:11 UTC 2013


> 
> 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!

nil is a pretty standard way of indicating nothing….

A decent comment would have solved this issue before it became an issue. 

Another way of implementing similar functionality without even having a class instance variable (wait a minute, is an instance variable of class Class a class variable or a class' instance variable or an instance of class class instance variable or what?) would just use normal method inheritance and global(ish) variables for the environments -

(root class)> environment
	^RootEnvironment

(some other class)>environment
	^SpecialEnvironment

Of course, you have to be able to look up SpecialEnvironment in your environment that applies when you compile that, which maybe isn't SpecialEnvironment? And obviously it doesn't allow for resetting the environment on the fly (except with a recompile)

But seriously, having code that says 
do I have Thing set? If so, return my Thing, otherwise return what my parent thinks Thing is 
is pretty common in any hierarchy. I really think that fixing it with a comment is the most useful answer. But then  I wouldn't accept a bit of code that didn't have a clear, meaningful comment in any code review.


tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Comment my code? Why do you think it's called 'code'?




More information about the Squeak-dev mailing list