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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 Articleif 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
More Pages to Explore .....