test bool value

  • Thread starter Thread starter simon
  • Start date Start date
S

simon

Hi all,

I found some code use the if(somefuction == bool) to test
the return bool value. What is the reason to do it
instead just if(somefunction)?

Thank you

Simon
 
Hi simon,
I found some code use the if(somefuction == bool) to test
the return bool value. What is the reason to do it
instead just if(somefunction)?

the only reason I could think of is that this particular programmer can read
it better that way. There's no other reason.

Regards,
 
Most rookies like to write it as: if(condition==true), which is fine
(usually it's beacause they either don't know it can be done the other way
and/or because they think it reads better).

Just writting if(condition) is what is generally more common and after using
it for a while, you'll begin to realize that it reads just as well but is
less code to write.
 
Hi Simon,
I found some code use the if(somefuction == bool) to test
the return bool value. What is the reason to do it
instead just if(somefunction)?

Now you can do (I do not know in what program language it is so some pseudo)

DoFunction(false)
DoFunction(bool) {
if (somefunction == bool) etc}

Cor
 
Easiness to understand.

Bools weren't always available. In some languages you had to declare them
yourself. So I depended on how users defined them (0= true, 1 =false OR 0 =
false, 1 = true OR ...). Doing a comparison without the == in such cases
would make it hard to understand what they meant.

Yves
 
Back
Top