On 24/07/2008, at 11:57 PM, Steve Lindsay wrote:

On Thu, Jul 24, 2008 at 11:37 PM, Adelle Hartley <[EMAIL PROTECTED]> wrote:

Run-on dereferencing - "SelectedCustomer.Country.Currency.ExchangeRate"

Is it normal? From what I've seen of other people's code, it's not all that common. Users seem to want to spell out every step. But then, I've spent a lot of time looking at Visual Basic and C# code and not much of anything
else.


What happens when the country for the particular customer is not
defined (is null)?

I was going to say, run-on dereferrencing is perfectly fine when you have a nice smart compiler/runtime that generates safe failures... and you're not actually dereferencing but invoking object methods to receive the next object in the chain...

ObjC is good this way.

The call would look something like this: [[[selectedCustomer country] currency] exchangeRate]

and ObjC has the rule that any message sent to the nil object returns nil, so if country returned a nil, the remaining messages would resolve as messages to nil which would result in nil...

you check for nil at the end and viola, no headache from having to check at every stage.

I believe smalltalk also has the same property as ObjC with respect to messages to nil.

The safe and sane programmer otherwise has to check for null or null pointer exceptions or language equivalent thereof at every dereference.

C.
--
Chris Collins <[EMAIL PROTECTED]>




_______________________________________________
coders mailing list
coders@slug.org.au
http://lists.slug.org.au/listinfo/coders

Reply via email to