Ad Code

Complex expressions should be written in multiple short statements

Why and how complex expressions should be written in multiple short statements, Explain it with example


Complex expressions should be broken down into multiple statements. An expression is considered to be complex if it uses many operators in a single statement. As an example consider the following statement:

*x += (*xp=(2*k < (n-m) ? c[k+1] : d[k--]));

This statement liberally uses a number of operators and hence is very difficult to follow and understand. If it is
broken down into simple set of statements, the logic becomes easier to follow as shown below:

if (2*k < n-m)
*xp = c[k+1];
else
*xp = d[k--];
*x = *x + *xp;
Reactions

Post a Comment

0 Comments