Any reason for assigning block parameter in inject:into:

nicolas cellier ncellier at ifrance.com
Sun Apr 29 13:00:02 UTC 2007


However, this pattern should be limited to very few optional args, 
because N optional args make (2 raisedTo: N) different messages.
That's a lot of code to maintain.

Nicolas

J J a écrit :
> I think JavaScript et al. need that because they don't have method 
> overloading or keyword arguments like Smalltalk does.  The patten 
> mentioned below simply isn't needed.  Instead of doing the below you 
> just do:
> 
> start: function element: el speed: sp duration: dur after: af
>  "..."
> 
> start: function element: el
>  ^ self start: function element: el speed: 0.4 duration: 0.4 after: 
> (function)
> 
> "etc."
> 
> To me this is much more elegant and clean then the ugly, perl-esque: 
> "var = var || default"  stuff.
> 
>> From: "Lukas Renggli" <renggli at gmail.com>
>> Reply-To: The general-purpose Squeak developers 
>> list<squeak-dev at lists.squeakfoundation.org>
>> To: "The general-purpose Squeak developers 
>> list"<squeak-dev at lists.squeakfoundation.org>
>> Subject: Re: Any reason for assigning block parameter in inject:into:
>> Date: Sun, 29 Apr 2007 11:36:16 +0200
>>
>>> There's absolutely no way that assigning to a block arg should be
>>> permitted. Blocks arg should be treated the same as method parameters
>>> by the compiler.
>>
>> A question: Why shouldn't it be allowed to assign to method and block
>> arguments, if the underlying implementation allows to do so?
>>
>> I wonder, because in other languages like JavaScript it is a very
>> common pattern to assign to function arguments, for example to set
>> default values if necessary. Personally I find this more clear and
>> less error prone than to introduce new temporary variables for the
>> arguments:
>>
>>     start: function (element, speed, duration, after) {
>>         element = $(element);
>>         speed = speed || 0.4;
>>         duration = duration || 4.0;
>>         after = after || function () { return true; };
>>         ...
>>
>> Cheers,
>> Lukas
>>
>> -- 
>> Lukas Renggli
>> http://www.lukas-renggli.ch
>>
> 
> _________________________________________________________________
> Mortgage rates near historic lows. Refinance $200,000 loan for as low as 
> $771/month* 
> https://www2.nextag.com/goto.jsp?product=100000035&url=%2fst.jsp&tm=y&search=mortgage_text_links_88_h27f8&disc=y&vers=689&s=4056&p=5117 
> 
> 
> 
> 




More information about the Squeak-dev mailing list