Any reason for assigning block parameter in inject:into:

brad fowlow fowlow at pacbell.net
Mon Apr 30 03:31:54 UTC 2007


I don't think it's quite that.

Assigning simply to parameters is rarely if ever 'magical'
in reaching up the call chain.  (Among widespread languages,
one exception is the goulash of C++ reference parameters;
I can't think of others offhand.)

For the workaday C programmer,
there's a very big difference between arg = 3; and (*arg) = 3.
The distinction between 'what's in the local parameter' and
'what I have to do to change longer-lived state'
is always front and center in low-level languages.

I don't think the real confusion that's avoided
by barring assignment-to-arguments
isn't that of someone writing
	param := foo
and expecting non-local effects up the call chain.

Rather it's the confusion of sorting out what's going on in a piece  
of code
when someone's decided variable names are too much work to invent,
and reused parameter names for other quantities along the way.

When you're reading a piece of unfamiliar code, every bit of solid  
ground helps;
knowing that the value of a parameter doesn't change in the course
of the method makes it that much easier to read and debug.

- brad


>  I wonder if this is a sign of changing times. After all,  
> "confusion" is a mismatch between expectations and reality. Perhaps  
> were seeing a change in expectations? Back in the days of yore,  
> people were coming to Smalltalk from low-level languages where it  
> was possible to pass pointers around, and returning a value through  
> a pass-by-reference parameter was a common idiom. These days,  
> people who are interested in Smalltalk are probably coming from  
> other dynamic languages where that's not possible, and treating  
> parameters as just another temp feels natural.
>
> Personally, I think it would be nice to be able to write to  
> parameter slots, but it's not worth breaking compatibility with  
> other Smalltalks.
>
> Colin
>




More information about the Squeak-dev mailing list