Software Engineering discussion
Code Complete
>
Organizing Straight-Line Code
date
newest »

message 1:
by
[deleted user]
(new)
Apr 13, 2011 07:08PM
This chapter is so short that I am afraid that any comment I would make would be longer than the chapter itself!
reply
|
flag


int main()
{
double a, b, c, x, y, z;
x = 1.2e+30;
y = -1.2e+30;
z = 2.3;
a = x + y;
b = x + z;
c = y + z;
printf("%f %f %f\n", a+z, b+y, c+x);
printf("%f %f %f\n", x+y+z, x+z+y, y+z+x);
return 0;
}
If you don't want to lose the value of z due to roundoff, you need to be able to control the order in which x + y + z is calculated.

None of the solutions suggested comments or documentation describing the dependancies either.
The code solution examples didn't seem that great to me. They don't imply a dependant order.
Something like this might even be better than this chapter's examples:
result = AnnualAccumulate( QuarterAccumulate( MonthAccumulate( data ) ) );
I feel this implies imporatnce of order and dependancy more the examples in this chapter.