General discussion

Locked

Using short-circuiting operators

By editor's response ·
Tell us what you think about the value of using short-circuiting operators, as featured in the August 12th Java e-newsletter. Have short-circuiting operators improved performance and simplified your code?

This conversation is currently closed to new comments.

4 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Null Object

by kevlin In reply to Using short-circuiting op ...

Sometimes the answer that leads to cleaner code is not to change your style of evaluation, but to change what you are evaluating. There are cases when a check for null can be eliminated easily by introducing the Null Object pattern:

http://www.two-sdg.demon.co.uk/curbralan/papers/europlop/NullObject.pdf

Kevlin

Collapse -

Bad link

by rsalcedo In reply to Null Object

Kevlin,

I was interested in reading the document you mentioned, but the link is not valid. Do you know where else it can be found?

-Ricardo

Collapse -

Bad link

by rsalcedo In reply to Null Object

Never mind,
I found it one level up in the directory tree:

http://www.two-sdg.demon.co.uk/curbralan/papers/NullObject.pdf

Collapse -

Null Pattern

by bayard In reply to Null Object

Definitely. The Null pattern is a great way to eliminate NullPointerExceptions from occuring in your code. [As described in builder.com/TechRepublic e-newsletter dated Mon, 5 Nov 2001, though I'm not aware of an archive to link you to ].

Simple example being, when you ask your person-loading code for a person, and the ID you ask for isn't there, it returns NullPerson and not null. NullPerson is a legal person whose name is "" etc.

Hen

Back to Web Development Forum
4 total posts (Page 1 of 1)  

Related Discussions

Related Forums