Message Eating Null - article

J J azreal1977 at hotmail.com
Thu Jul 26 18:56:02 UTC 2007


> Date: Wed, 25 Jul 2007 16:58:49 +0100> From: keith_hodges at yahoo.co.uk> To: squeak-dev at lists.squeakfoundation.org> Subject: Message Eating Null - article> > To contrast this, how then would you have to code it if nil has the > "exception throwing" behavior? You would do> it similar to this:> >   | tmp |>    tmp := person office.>    tmp notNil ifTrue: [tmp := tmp phone].>    tmp notNil ifTrue: [tmp := tmp lastNumberDialed].>    tmp notNil ifTrue: [lastNumber := tmp asString].>    widget setStringValue: lastNumber.> > Yuck...all those explicit tests for nil are really ugly! Of course, you > could have instead wrapped the original code> in an exception handler, and thus avoided the nil tests, something like > as follows:> >    [lastNumber := person office phone lastNumberDialed asString.>    widget setStringValue: lastNumber]>       on: Object messageNotUnderstoodSignal do: [].> > This looks a bit simpler than the previous example, but even this > example contrasts poorly to the first example.> The first example of these three is much simpler! You just "do it", > without worrying about exceptions, exception> handlers, or explicit tests.Yuck, I wouldn't do either of those.  I would do:widget setStringValue: #(office phone lastNumberDialed asString) inject: person into: [:obj :sel| o == nil ifTrue: [ nil ] ifFalse: [ obj sel ] ]
_________________________________________________________________
Local listings, incredible imagery, and driving directions - all in one place! Find it!
http://maps.live.com/?wip=69&FORM=MGAC01
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20070726/0c8d33ef/attachment.htm


More information about the Squeak-dev mailing list