book/The Practice of Programming

1.2 Expressions and Statements

헤써니 2015. 12. 21. 02:50

Indent to show structure.

BAD CASE

for(n++;n<100;field[n++]='\0');

*i = '\0'; return('\n');


GOOD CASE

for(n++; n<100; n++)

field[n] = '\0';

*i = '\0';

return '\n';


Even better is to put the assignment in the body and separate the increment, 

so the loop takes a more conventional form and is thus easier to grasp.


Use the natural form for expressions.

Conditional expressions that include negations are always hard to understand.


BAD CASE

if(!(a < b) || !(b <= c))


GOOD CASE

if((a >= b)||(b > c))



Parenthesize to resolve ambiguity.


Break up complex expressions.


Be clear.


Be careful with side effects.



WORD

Parenthesize 괄호 안에 넣다