PDA

View Full Version : How do YOU style it?


xXziroXx
01-30-2007, 03:21 AM
Ive been curious about whats the most common styling with using true/false variables, so I figured Id make a poll about it.



Alternative A:


if (this.var == true)
if (this.var == false)



Alternative B:


if (this.var)
if (!this.var)



I, personally, go with alternative A.

Gambet
01-30-2007, 03:26 AM
I actually just style it depending on how I feel like doing it.

But, mostly, I believe I do Alternative B, though sometimes I do stuff like



if (!(this.var))

JkWhoSaysNi
01-30-2007, 03:26 AM
B...

Why check a boolean variable is true and then have the if statement check the result of that?

B just seems more efficient.

Tolnaftate2004
01-30-2007, 05:01 AM
B...

Why check a boolean variable is true and then have the if statement check the result of that?

B just seems more efficient.

Ditto.

I also like to do stuff like
temp.p = string.pos(substr);
if (~temp.p)
if (!~temp.p)

_Z3phyr_
01-30-2007, 05:11 AM
Personally I'm a fan of the cutoff look

Chandler
01-30-2007, 09:55 AM
Option B

DrakilorP2P
01-30-2007, 11:07 AM
I tend to go with B, especially when the variable name makes sense, such as this.pathIsBlocked.

xXziroXx
01-30-2007, 11:09 AM
Haha, im totally in a minority here..

Chompy
01-30-2007, 03:50 PM
I tend to go with B, especially when the variable name makes sense, such as this.pathIsBlocked.
agreed :)

Crow
01-30-2007, 03:58 PM
Didnt vote for anything because of...

if (this.var == 1)
if (this.var != 1)

godofwarares
01-30-2007, 09:45 PM
I prefer alternative A, because you find things better and its more comprehensive =]

Skyld
01-30-2007, 09:47 PM
I normally use (and prefer to use) B, since there is little point in the engine essentially doing (var == true) == true, not sure if it's folded in the bytecode.

I do use A sometimes, though.

Admins
01-30-2007, 10:03 PM
I prefer B, I think A comes from C++ where it sometimes looks better when you show that you make a boolean comparison and not some check-for-valid-pointer hack.
A is also slower although the comparions-operation is not really that slow. It looks a little bit weird to compare with true or false though, "if (true==true)"

godofwarares
01-30-2007, 10:06 PM
I prefer B, I think A comes from C++ where it sometimes looks better when you show that you make a boolean comparison and not some check-for-valid-pointer hack.
A is also slower although the comparions-operation is not really that slow. It looks a little bit weird to compare with true or false though, "if (true==true)"

That would be a bit wierd, I always use while / if (true); So I suppose I alternate between A and B =]

Inverness
01-30-2007, 11:20 PM
I prefer A since I like the way it looks.

Andy0687
01-31-2007, 08:13 AM
I prefer method A.

However recently I found myself using method B because there is a bit less to type.