I always use If statement (In C#) as (1. Alternative);
if (IsSuccessed == true)
{
//
}
I know that there is no need to write \"== true\"
I used to write "== true" because I thought it was clearer and more explicit, but decided to change. Now it always seems much clearer without, you'll just get used to it.
I'll go for the second. It's easier for me at least. In the first alternative I always wonder why the comparison is made. Check the type of the left hand side just to be sure that no developer on acid overloaded the == operator making comparison between his class and bool an option.
The first also leads to bugs the second won't.
if(a)
might need to be change to if(a||b)
or if(a&&b)
in the first version it might end up as if(a == true || b)
and if(a == true && b)
in the former b
is redundant and the latter equals if(a==b)
What i see most is: (what I do)
if (IsSuccessed)
{
//
}
and as alternative for in C++, for C# it's not needed (see comment):
if (true == IsSuccessed)
{
//
}
The alternative is to prevent yourself for making the mistake to assign instead of compare. (= vs ==)
I'd personally go for the second option. It reads more naturally and shows that a programmer is actually aware of a built-in bool
type, which is a first-class citizen.
Totally style dependant. Seriously. Go with whatever you like for your own stuff, whatever is the enfoced style at your work.
More typing means more chances for bugs. Option 2 all the way...