Is variable shadowing a feature or a bug?
I just discovered that in Pharo 3 you can do: [ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true Is this a bug or a feature ? I am fighting with this every day in javascript, and I do not know about to feel about this :s Ben
On 12 December 2013 14:44, Benjamin <Benjamin.VanRyseghem.Pharo@gmail.com> wrote:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
That's not a shadow, from what I can see? It is an assign-to-a-block-argument, which I'd frown upon. | bool | bool := true. [:bool | "<-- shadow!" self logCr: bool] value: bool is a shadow. Unless I'm missing something? frank
I am fighting with this every day in javascript, and I do not know about to feel about this :s
Ben
Looks like a bug to me :) Nico Benjamin writes:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
I am fighting with this every day in javascript, and I do not know about to feel about this :s
Ben
-- Nicolas Petton http://nicolas-petton.fr
On 12 Dec 2013, at 15:53, Nicolas Petton <petton.nicolas@gmail.com> wrote:
Looks like a bug to me :)
Yes, the argument should not be writableâ¦
Nico
Benjamin writes:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
I am fighting with this every day in javascript, and I do not know about to feel about this :s
Ben
-- Nicolas Petton http://nicolas-petton.fr
On 12 Dec 2013, at 15:44, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
https://pharo.fogbugz.com/f/cases/12419/block-arguments-should-be-read-only
On Thu, Dec 12, 2013 at 7:03 AM, Marcus Denker <marcus.denker@inria.fr>wrote:
On 12 Dec 2013, at 15:44, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
https://pharo.fogbugz.com/f/cases/12419/block-arguments-should-be-read-only
except that it didn't used to be a bug pre closures, so *if* its important to be able to load old code this should be made a preference which is by default on. i.e. by default assigning to any argument is an error, but the preference can be set to allow assignments to block args. At least IIRC that's how it is in Squeak right now. -- best, Eliot
On 12 December 2013 19:04, Eliot Miranda <eliot.miranda@gmail.com> wrote:
On Thu, Dec 12, 2013 at 7:03 AM, Marcus Denker <marcus.denker@inria.fr> wrote:
On 12 Dec 2013, at 15:44, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
https://pharo.fogbugz.com/f/cases/12419/block-arguments-should-be-read-only
except that it didn't used to be a bug pre closures, so *if* its important to be able to load old code this should be made a preference which is by default on. i.e. by default assigning to any argument is an error, but the preference can be set to allow assignments to block args. At least IIRC that's how it is in Squeak right now.
It is: "Allow block argument assignment", or Scanner >> #allowBlockArgumentAssignment, depending on where you look. frank
-- best, Eliot
On 12 Dec 2013, at 20:22, Frank Shearar <frank.shearar@gmail.com> wrote:
On 12 December 2013 19:04, Eliot Miranda <eliot.miranda@gmail.com> wrote:
On Thu, Dec 12, 2013 at 7:03 AM, Marcus Denker <marcus.denker@inria.fr> wrote:
On 12 Dec 2013, at 15:44, Benjamin <benjamin.vanryseghem.pharo@gmail.com> wrote:
I just discovered that in Pharo 3 you can do:
[ :bool | self logCr: bool. bool := false. self logCr: bool. ] value: true
Is this a bug or a feature ?
https://pharo.fogbugz.com/f/cases/12419/block-arguments-should-be-read-only
except that it didn't used to be a bug pre closures, so *if* its important to be able to load old code this should be made a preference which is by default on. i.e. by default assigning to any argument is an error, but the preference can be set to allow assignments to block args. At least IIRC that's how it is in Squeak right now.
It is: "Allow block argument assignment", or Scanner >> #allowBlockArgumentAssignment, depending on where you look.
Ok, I will do it with the Preference But in the long run, one can get rid of these things⦠e,g, Step one: code critic rule to detect these cases two: deprecate the code three: remove. Marcus
participants (6)
-
Benjamin -
Eliot Miranda -
Frank Shearar -
Marcus Denker -
Nicolas Petton -
Stéphane Ducasse