[squeak-dev] A lot of shadowed variable names in Squeak 6.0 needing clearing up

Levente Uzonyi leves at caesar.elte.hu
Sun Jan 1 00:20:07 UTC 2023


Hi Tim,

I have got no problem with shadowed variables. It's a feature to be able 
to shadow those variables.
If you want to get rid of them, then you should consider making the 
compiler raise an error instead of spamming the transcript with 
warning-looking messages. If you don't do so, they will creep back despite 
the current wave of cleanup.
But, since I like the feature, a better option would be to adjust 
the highlighting of such variables to make shadowing more obvious.

On Sat, 31 Dec 2022, tim Rowledge wrote:

> An excellent example is Random>>#nextBytes:into:startingAt:
>
> It refers to a temp named 'index' which shadows an instvar. Should the method be just using that instvar, or a different named temp? I *think* the latter but it's possible Levente would suggest otherwise. All I can be sure of is that the RandomTest class reports all ok.

In Random, shadowing is pretty much intentional.

The index instance variable is only accessed by private methods 
implementing the PRNG logic itself.
If you think the name is too generic, then you may want to rename it to 
nextStateIndex, as it holds to the index of the next state to generate 
the next random values.
>From the Random object's point of view, the name index is okay IMO.

In #nextBytes:into:startingAt:, index is obviously the running index of 
the ByteArray to be filled up with random values. So, it clearly should 
not touch the instance variable. If you don't like the name index, I 
suggest using currentIndex instead.

For the other methods of Random, I do not fancy calling variables "i".
I understand why it may be tempting to use single letters or 
abbreviations, especially without code completion, but I prefer 
descriptive names.
Also, RIP my beautiful methods :(. :)


Levente


More information about the Squeak-dev mailing list