optimization - Does if (myBool == true) differ computational wise to if(myBool)? -


i read coding style suggestion comparing bools said write

if (myboolvalue == true) { ... } if (myboolvalue == false) { ... } 

instead of writing

if (myboolvalue) { ... } if (!myboolvalue) { ... } 

since increases readability of code though equivalent statements. aware not usual coding practice agree may increase readability in cases.

my question if there difference between 2 in regards of optimization of code execution or if (a implemented) compiler translate them same thing?

the productions not same in languages.

for instance, may produce different results "non-boolean" values of "myboolvalue" in both javascript , c.

// javascript [] == true         // false [] ? true : false  // true  // c #define true 1 #define false 0 int x = -1; x == true         // 0 (false) x ? true : false  // true (1) 

to see specific compiler specific programming language (there both allowed , do), check generated assembly/machine/byte code.

(anyway, i prefer , use latter form exclusively.)


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -