J
Jean Lutrin
Hi,
Roedy, in another thread, you said that I should not write :
if (someBoolean == true) {...}
but simply :
if (someBoolean)
when working with a boolean primitive.
However I do find :
if (!someBoolean) {...}
to be much less readable than :
if (someBoolean == false) {...}
(and this is especially true, at least for me,
when the boolean has a lloonngg name, like :
isMD5ChecksumAvailable... it is easy
to forgot about the "!" or simply not to see
it, not that I advice using long names btw
And I know that there are others who prefer to
use the latter when doing such tests.
So my 2 Eurocents question is : would it make
sense in source code to use :
if (someBoolean) {...}
when testing for "true" and :
if (someBoolean == false)
when testing for false ?
I have to say we have strong guidelines here
at work (and I mainly established them, back in
the days, then refined them based on advices
given in the chapter in "Bitter Java"
devoted to this subject) and I would like to
know what is the "best" way to do it...
If I'm really motivated I could hack a little
grep/sed/whatever Unix script on the CVS server
we now all use (that I set up some weeks ago)
to see what the developers favor and if they
are consistent.
Statistics on this topic anybody ? Or guidelines ?
Cya later and, as usual, excuse my french
Jean
P.S : sometimes it is even clearer, at least
for me when I read it, to write :
if (... != true) {...}
instead of :
if (... == false) {...}
It all depends on the circumstances. Btw, it is
not "just about logic", I think that the fact
that my mother tongue is french means I "read"
the "english" code differently than an native
english speaker... So what may sounds redundant
for you may just seem "natural" for me. Of
course, I think that consistency is the most
important thing and that everybody should do
the same, because it facilitates team work
(then again my team is all french-speaking but
we don't use a single french comment nor a
single french class/variable/file names :
our naming convention is ASCII compliant
Roedy, in another thread, you said that I should not write :
if (someBoolean == true) {...}
but simply :
if (someBoolean)
when working with a boolean primitive.
However I do find :
if (!someBoolean) {...}
to be much less readable than :
if (someBoolean == false) {...}
(and this is especially true, at least for me,
when the boolean has a lloonngg name, like :
isMD5ChecksumAvailable... it is easy
to forgot about the "!" or simply not to see
it, not that I advice using long names btw
And I know that there are others who prefer to
use the latter when doing such tests.
So my 2 Eurocents question is : would it make
sense in source code to use :
if (someBoolean) {...}
when testing for "true" and :
if (someBoolean == false)
when testing for false ?
I have to say we have strong guidelines here
at work (and I mainly established them, back in
the days, then refined them based on advices
given in the chapter in "Bitter Java"
devoted to this subject) and I would like to
know what is the "best" way to do it...
If I'm really motivated I could hack a little
grep/sed/whatever Unix script on the CVS server
we now all use (that I set up some weeks ago)
to see what the developers favor and if they
are consistent.
Statistics on this topic anybody ? Or guidelines ?
Cya later and, as usual, excuse my french
Jean
P.S : sometimes it is even clearer, at least
for me when I read it, to write :
if (... != true) {...}
instead of :
if (... == false) {...}
It all depends on the circumstances. Btw, it is
not "just about logic", I think that the fact
that my mother tongue is french means I "read"
the "english" code differently than an native
english speaker... So what may sounds redundant
for you may just seem "natural" for me. Of
course, I think that consistency is the most
important thing and that everybody should do
the same, because it facilitates team work
(then again my team is all french-speaking but
we don't use a single french comment nor a
single french class/variable/file names :
our naming convention is ASCII compliant