Where would you put the return?

Jarvis, Robert P. (Contingent) Jarvisb at timken.com
Tue May 20 12:18:13 UTC 2003


> -----Original Message-----
> From: Andreas Raab [mailto:andreas.raab at gmx.de]
> Sent: Monday, May 19, 2003 5:06 PM
> To: 'The general-purpose Squeak developers list'
> Subject: RE: Where would you put the return?
> 
> 
> > > 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!).
> > 
> > Interesting.  So why do methods answer self by default?
> 
> Beats me.

Well, since answering 'nil' if no explicit answer is provided is obvious,
and answering 'self' is not, maybe there's a reason why the non-obvious
solution was adopted.  Dan or Alan - if you're listening, would you care to
comment?  Is answering 'self' a holdover from earlier (pre-80) versions of
Smalltalk where, perhaps, explicit message cascades weren't available?
Or..?  And how much code would this change break?  (Yeah, I know - burn the
disk packs...).

>But if I see that a method has no return statement 
> then I think
> that 'this method returns nothing'. And 'nothing' is nil - 
> the undefined
> object. Besides, returning self by default is a horrible mess 
> when you think
> about security as you are constantly leaking authority.

If a message sent to an object answers that same object how is authority
'leaked'?  Put another way, what does the sender of the message know after
the message is sent that he didn't know before the message was sent, and how
would answering 'nil' rather than 'self' improve the situation?

Bob Jarvis
Compuware @ Timken


**********************************************************************
This message and any attachments are intended for the 
individual or entity named above. If you are not the intended
recipient, please do not forward, copy, print, use or disclose this 
communication to others; also please notify the sender by 
replying to this message, and then delete it from your system. 

The Timken Company
**********************************************************************



More information about the Squeak-dev mailing list