I have always written my boolean expressions like this:
if (!isValid) {
// code
}
But my new employer insists on the following style:
if (false == isValid) {
// code
}
Is one style preferred, or standard?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I prefer the first style because it is more natural for me to read. It’s very unusual to see the second style.
One reason why some people might prefer the second over another alternative:
is that with the latter you accidentally write a single
=instead of==then you are assigning to isValid instead of testing it but with the constant first you will get a compile error.But with your first suggestion this issue isn’t even a problem, so this is another reason to prefer the first.