Software Engineering discussion
Code Complete
>
Organizing Straight-Line Code
date
newest »
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
In my opinion the very first example where output from one procedure is passed to the next one is the best for indicating execution order to code reader. From code reader’s or modifier’s perspective I would not make any assumptions about code execution order, so at first I thought may be it’s a useless suggestion. But from the constructor’s perspective this is a great idea to make it harder for somebody else to change an order of execution if it’s important to keep it in order. I mean, even if changing order of execution is required to fix a problem, doing more work will require a person to understand the original idea or at least allow more time for consideration.
Order of execution is sometimes critical, and the programmer should be able to have a mechanism to control it. Consider the following code I show all of my C students: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.
I was looking for a solution that somehow factored the accumulation examples in to a new class or a single function.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.

