Quantcast
Channel: if statement - short circuit evaluation vs readability - Stack Overflow
Browsing latest articles
Browse All 11 View Live

Answer by Dominique for if statement - short circuit evaluation vs readability

Very strange: you are talking about readability when nobody mentions the usage of comment within the code:if (somecomplicated_function() || // let me explain what this function does...

View Article



Answer by levilime for if statement - short circuit evaluation vs readability

Another possibility that short circuits and has the conditions in one place:bool (* conditions [])()= {&a, &b, ...}; // list of conditionsbool conditionsHold = true;for(int i= 0; i <...

View Article

Answer by AmigoJack for if statement - short circuit evaluation vs readability

I tend to break down conditions onto multiple lines, i.e.: if( SomeComplicatedFunctionCall() || OtherComplicatedFunctionCall() ) {Even when dealing with multiple operators (&&) you just need to...

View Article

Answer by KIIV for if statement - short circuit evaluation vs readability

You can also use:bool b = someComplicatedStuff();b = b || otherComplicatedStuff(); // it has to be: b = b || ...; b |= ...; is bitwise OR and SCE is not working then and SCE will work.But it's not much...

View Article

Answer by songyuanyao for if statement - short circuit evaluation vs readability

1) Do I really lose SCE every time? Is compiler is some scenario allowed to "optimize it" and still provide SCE?I don't think such optimization is allowed; especially OtherComplicatedFunctionCall()...

View Article


Answer by br0lly for if statement - short circuit evaluation vs readability

Readability is necessary if you work in a company and your code will be read by someone else. If you write a program for yourself, it is up to you if you want to sacrifice performance for the sake of...

View Article

Answer by Some programmer dude for if statement - short circuit evaluation vs...

If you have long chains of conditions and what to keep some of the short-circuiting, then you could use temporary variables to combine multiple conditions. Taking your example it would be possible to...

View Article

Answer by Hatted Rooster for if statement - short circuit evaluation vs...

1) Do I really lose SCE every time? Is compiler is some scenario allowed to "optimize it" and still provide SCE?No you don't, but it's applied differently:if (SomeComplicatedFunctionCall() ||...

View Article


Answer by SJuan76 for if statement - short circuit evaluation vs readability

1) Yes, you no longer have SCE. Otherwise, you would have that bool b1 = SomeComplicatedFunctionCall();bool b2 = OtherComplicatedFunctionCall();works one way or the other depending if there is an if...

View Article


Answer by Horia Coman for if statement - short circuit evaluation vs readability

One natural solution would look like this:bool b1 = SomeCondition();bool b2 = b1 || SomeOtherCondition();bool b3 = b2 || SomeThirdCondition();// any other conditionbool bn = bn_1 ||...

View Article

if statement - short circuit evaluation vs readability

Sometimes, an if statement can be rather complicated or long, so for the sake of readability it is better to extract complicated calls before the if.e.g. this:if (SomeComplicatedFunctionCall() ||...

View Article
Browsing latest articles
Browse All 11 View Live




Latest Images