Where would you put the return?

Andreas Raab andreas.raab at gmx.de
Mon May 19 19:29:22 UTC 2003


> What do you think of lazy initializers written like:
> 
> something
> 
>     ^something ifNil: [something := 'initial value'].

That's one of the cases where I like it, though -to be honest- it's not
quite clear to me why. I think it's mostly because I tend to think about
#ifNil: as effectively having no 'alternative branch' (I know there's
#ifNil:ifNotNil: and in this case I would not like it ;) Perhaps it's just
the usage pattern - when you learn #ifTrue:ifFalse: you think about it more
as a 'control structure' with multiple branches whereas when you learn about
#ifNil: you probably learn about it as not having multiple branches. Or,
perhaps it's just that I think a method with no explicit return statement
should return nil instead of self (and _that_ I think very strongly!).

I don't know.

Cheers,
  - Andreas



More information about the Squeak-dev mailing list