in Random class #index inst var is shadowed in 3 methods

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

in Random class #index inst var is shadowed in 3 methods

Paul DeBruicker

Would that change the behavior of the methods?  


It doesn't seem to as the tests pass if you rename the index temp vars to idx.


Why is that?


Thanks

Paul





Random.pad.1.cs (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: in Random class #index inst var is shadowed in 3 methods

marcel.taeumel
Hi Paul,

your change set works fine here in Squeak Trunk in Windows 10. Random-Tests pass before and after file-in.

Best,
Marcel
Reply | Threaded
Open this post in threaded view
|

Re: in Random class #index inst var is shadowed in 3 methods

Levente Uzonyi
In reply to this post by Paul DeBruicker
On Wed, 11 May 2016, PAUL DEBRUICKER wrote:

>
> Would that change the behavior of the methods?
>
>
> It doesn't seem to as the tests pass if you rename the index temp vars to idx.
>
>
> Why is that?
>

Because shadowing means that the shadowed variable will not be used. Since
those methods don't use the instance variable, it's perfectly fine to
reuse the name "index" instead of "idx" or "i" or whatever.

Levente

>
> Thanks
>
> Paul
>
>
>