optimization - What advantage is gained by placing a literal value on the LHS of a boolean expression? -
optimization - What advantage is gained by placing a literal value on the LHS of a boolean expression? -
i've noticed subtle trend among developers consistently place literal value of boolean equality look on left hand side of expression.
example:
//style #1, style in question if (null == object.value || 0 == object.value) dosomething(); //style #2, way i've written if (object.value == null || object.value == 0) dosomething(); is there measurable advantage gained writing boolean expressions #1? can't see why evaluate faster @ runtime, wonder if perhaps compilers can optimize #1 more readily #2? if so, please explain compilers , why.
i've considered matter of personal taste (perhaps there readability argument made), i've seen plenty code written #1 wonder if there more i'm aware of.
some developers follow , advocate (1) if accidentally mis-type comparing (==) assignment (=), compiler issue error during compilation. in (2) same mis-typing not issue compilation error, result in flawed programme logic because if resolve true due assignment.
optimization coding-style
Comments
Post a Comment