Yes and no.
First off, to those who say no to the situation with no exceptions, I challenge you to find a situation where a coding convention fits all use cases. This is no different.
Now in a situation where you have a simple expression being evaluated I would not add == true
to the code. It is largely self explanatory and I know my coworkers would understand what is happening without much though. In addition you may fall into the debugging joy that is writing var = true
rather than var == true
.
while (flag) {
// iterate
}
In a situation where you have a function inside of the comparison, unless the method is of the isSomeCondition()
variety, I would add the == true
. In my opinion doing so with an ambiguous method makes it more clear what you expect the code to be. After all, it is easy to miss a !
.
while (largeAmbiguousCheckingMethod(input) == true) {
}
In this situation you should immediately know what the intent is, assuming a well name method, and you do not run into the problem of accidental assignment.