Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   How do YOU style it? (https://forums.graalonline.com/forums/showthread.php?t=71809)

xXziroXx 01-30-2007 03:21 AM

How do YOU style it?
 
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:

PHP Code:

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


Alternative B:

PHP Code:

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


PHP Code:

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

Quote:

Originally Posted by JkWhoSaysNi (Post 1271140)
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
PHP Code:

temp.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

Quote:

Originally Posted by DrakilorP2P (Post 1271247)
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...

PHP Code:

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

Quote:

Originally Posted by Stefan (Post 1271391)
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.


All times are GMT +2. The time now is 10:59 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.