Binary expressions

IDCC-15
TitleBinary expressions should not make an assumption on the evaluation order of their operands.
PriorityStrongly recommended
Severity level5
DescriptionBinary expressions should not make an assumption on the evaluation order of their operands. Generated code does not enforce the order of evaluation in expressions. It is therefore advised to define variables to enforce a specific evaluation order. For more info, see The Mathworks.
RationaleRobustness

avoid

 if (aFcnCall(z) || anotherFcnCall(z))

instead use

First compute the intermediate results in desired order:

isApprovedForA = aFcnCall(z); 
isApprovedForB = anotherFcnCall(z); 

 if (isApprovedForA || isApprovedForB)

or in case you really need the conditional execution:

isApproved = aFcnCall(z); 

if (~isApproved)
   % not yet approved
   isApproved = anotherFcnCall(z); 
else
   % allready approved
end

if (isApproved)