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