Where would you put the return?

Andreas Raab andreas.raab at gmx.de
Mon May 19 18:37:35 UTC 2003


Hi Benoit,

In most cases I prefer the first version with explicit returns as it tells
the reader what exactly is being returned. I find it *terribly* problematic
to see code like

	^foo = bar ifTrue:[42]

as it doesn't tell me what is being returned if it's false (and no it does
not return 'self' it returns 'nil' - ho hum...). So in this sense I find
explicit returns *much* more expressive here and in many cases I would claim
such changes to be an obfuscation rather than a 'cleanup' (as in: more
readable, better to understand).

Cheers,
  - Andreas

> -----Original Message-----
> From: squeak-dev-bounces at lists.squeakfoundation.org 
> [mailto:squeak-dev-bounces at lists.squeakfoundation.org] On 
> Behalf Of Benoit St-Jean
> Sent: Monday, May 19, 2003 6:54 PM
> To: Squeak Mailing List
> Subject: Where would you put the return?
> 
> 
> While we're in KCP mode, I was wondering if there was
> any good reason for the following code in
> Object>>#isKindOf:
> 
> isKindOf: aClass 
> 	"Answer whether the class, aClass, is a superclass or
> class of the 
> 	receiver. "
> 	self class == aClass
> 		ifTrue: [^ true]
> 		ifFalse: [^ self class inheritsFrom: aClass].
> 
> 
> Why isn't it written like that:
> 
> ^self class == aClass
> 		ifTrue: [true]
> 		ifFalse: [self class inheritsFrom: aClass].
> 
> Just curious.  You can find similar "multiple returns"
> in a few places in the image...  Not really important
> but I prefer the "cleaner" version...
> 
> My 2 cents.
> 
> 
> =====
> -----------------
> Benoit St-Jean
> Yahoo! Messenger: bstjean
> A standpoint is an intellectual horizon of radius zero. -- 
> Albert Einstein
> 



More information about the Squeak-dev mailing list