aspose file tools*
The moose likes Cattle Drive and the fly likes negated boolean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "negated boolean" Watch "negated boolean" New topic
Author

negated boolean

Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Nitpicking myself page http://www.javaranch.com/CodeBarn/BarnLoadGifMsg.jsp

;-)
[Marilyn added code tags]

[This message has been edited by Marilyn deQueiroz (edited February 23, 2001).]
Johannes de Jong
tumbleweed
Bartender

Joined: Jan 27, 2001
Posts: 5089
Why would (should) you avoid using the ! (not)
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
I used this construction in one of my solutions and
was advised to not use !boolean.
Peter
Joe Von
Ranch Hand

Joined: Feb 22, 2001
Posts: 32
I believe that the motivation behind avoiding the negated boolean is simply readablity.
It is simpler and more understandable to reverse the if / else statement. A future reader will have an easier time with an
"if TRUE" than with an "if not TRUE" construction.
Of course, the functionality is the same both ways, but you always want to assume that sometime in the future some drooling moron will need to understand and modify your code. And you should try and help the poor benighted sod.
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20636
    ∞

We will make the change to the code. Good catch!


permaculture Wood Burning Stoves 2.0 - 4-DVD set
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Thanks, Peter. It's changed.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Peter Gragert
Ranch Hand

Joined: Jan 16, 2001
Posts: 424
Suggestion of my son:
If the then part is very long and the else part is short
it may be meaningful to use a negated boolean, because
one can see this 'easy' agaist 'difficult' part with just
opening your eyes.
Comments?
paul wheaton
Trailboss

Joined: Dec 14, 1998
Posts: 20636
    ∞

Then the if part needs to be in a seperate method.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: negated boolean