File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

negated boolean

 
Peter Gragert
Ranch Hand
Posts: 424
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5089
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would (should) you avoid using the ! (not)
 
Peter Gragert
Ranch Hand
Posts: 424
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used this construction in one of my solutions and
was advised to not use !boolean.
Peter
 
Joe Von
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 21187
Firefox Browser IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We will make the change to the code. Good catch!
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Peter. It's changed.
 
Peter Gragert
Ranch Hand
Posts: 424
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 21187
Firefox Browser IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the if part needs to be in a seperate method.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic