[Pharo-project] Exception >> return:?
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? camillo
Some Smalltalks required it (i.e. VA), that's probably also the reason why SUnit uses it. Likely has to do with how they implement exception handlers. Lukas On Tuesday, 19 July 2011, Camillo Bruni <camillo.bruni@inria.fr> 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?
camillo
-- Lukas Renggli www.lukas-renggli.ch
thanks ;) On 2011-07-19, at 17:23, Lukas Renggli wrote:
Some Smalltalks required it (i.e. VA), that's probably also the reason why SUnit uses it. Likely has to do with how they implement exception handlers.
Lukas
On Tuesday, 19 July 2011, Camillo Bruni <camillo.bruni@inria.fr> 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?
camillo
-- Lukas Renggli www.lukas-renggli.ch
On Tue, Jul 19, 2011 at 8:19 AM, Camillo Bruni <camillo.bruni@inria.fr>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).
camillo
-- best, Eliot
2011/7/19 Eliot Miranda <eliot.miranda@gmail.com>
On Tue, Jul 19, 2011 at 8:19 AM, Camillo Bruni <camillo.bruni@inria.fr>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
participants (4)
-
Camillo Bruni -
Eliot Miranda -
Lukas Renggli -
Nicolas Cellier