Any reason for assigning block parameter in inject:into:

J J azreal1977 at hotmail.com
Sun Apr 29 10:31:08 UTC 2007


Not to mention the interface is much nicer the Smalltalk way.

someObj start: [ "do stuff" ] element: someElement.

vs.

someObj start: [ "do stuff" ] element: someElement speed: nil duration: nil 
after: nil. "????"

Personally I have not yet seen a case in a language like Smalltalk where 
wanting to assign to a passed parameter wasn't a sign that some refactoring 
was needed.

>From: "J J" <azreal1977 at hotmail.com>
>Reply-To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>To: squeak-dev at lists.squeakfoundation.org
>Subject: Re: Any reason for assigning block parameter in inject:into:
>Date: Sun, 29 Apr 2007 10:24:34 +0000
>
>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
>
>

_________________________________________________________________
Get a FREE Web site, company branded e-mail and more from Microsoft Office 
Live! http://clk.atdmt.com/MRT/go/mcrssaub0050001411mrt/direct/01/




More information about the Squeak-dev mailing list