2011/7/19 Eliot Miranda <[email protected]>

>
>
> On Tue, Jul 19, 2011 at 8:19 AM, Camillo Bruni <[email protected]>wrote:
>
>> Can anyone explain me why it would make sense to use #return: in the
>> following method?
>>
>> TestCase >> executeShould: aBlock inScopeOf: anExceptionalEvent
>>        ^[aBlock value.
>>           false]
>>                on: anExceptionalEvent
>>                do: [:ex | ex return: true]
>>
>> I would instinctively replace [:ex | ex return: true] with the much
>> simpler [:ex | ^ true]..
>> Am I missing something here?
>>
>
> Well, Lukas' answer makes sense to me.  But on a style point I would
> replace it by the even simpler
>
> TestCase >> executeShould: aBlock inScopeOf: anExceptionalEvent
>        ^[aBlock value.
>           false]
>                on: anExceptionalEvent
>                do: [:ex | true]
>
> the explicit non-local return ^true isn't necessary, sicne there's already
> a method return for the whole on:do: form, and in some implementations the
> [:ex| ^true] block could be significantly more expensive to create than
> [:ex| true] (e.g. VisualWorks, but not current Squeak/Pharo with my closure
> implementation).
>
> And the shortest Squeak form is
TestCase >> executeShould: aBlock inScopeOf: anExceptionalEvent
       ^[aBlock value.
          false]
               on: anExceptionalEvent
               do: [ true ]


>
>> camillo
>>
>>
>
>
> --
> best,
> Eliot
>
>

Reply via email to