Thu, 10 Dec 1998 16:16:59 -0500
> The benefit is to the next guy that has to modify the code. If the
> package is already there, then when something which was only used by a
> single subprogram is needed by another, "lifting" the variable is much
I agree with this point. However, I would not be likely to use this
nesting method if there was the remotest chance one of my subprograms
could ever be a candidate for re-use. It is just in contrast to the
method some people use of writing 4,000 SLOC straight line procedures.
It's kind of like making the parent procedure a table of contents to the
substeps--only it's at the end. Or like the parent is the "what" and the
nested routines are the "how". In other words, it's not a modularity or
factoring technique, it's just a way of avoiding the alternate example
I generally use this technique only when it's obvious that there will
never be any need to "lift" a routine to a higher nesting level. As for
lifting variables, it's just as easy to lift a variable from a nested
routine to the parent routine.
I have seen this technique used by others in C. The problem there is the
lack of nesting making the substeps visible where they shouldn't be.
procedure Trip is -- the example I was trying NOT to use
begin -- Trip
for I in 1 .. 100 loop -- Why do people find 'Range so hard to use?
Put (Suitcase(I), Car);
if -- no more suitcases
exit; -- same question for exit when...
-- back out
Put (Key, Ignition);
... (ten more SLOC to get out of driveway)
-- go to onramp
... (ten more to point the car north, move it, find the ramp)
-- get on highway
(ten SLOC to get on the highway)
(ten more SLOC)
(twenty SLOC, every other one being Check For and Avoid_Wolf)
(forty SLOC, including if's nested five deep to select the gas station)
-- Lecture_Kids_About Manners
Topic := Manners;
-- lecture kids about fighting
Topic := Fighting;
(same five SLOC)
-- Lecture_Kids_About begging for candy
Topic := Begging_For_Candy;
(same five SLOC)
-- ten more SLOC to "arrive at Grandmas"
-- notice people that do this don't believe in blank lines either?
-- it's like a two Kilobyte assembly language program with no subroutine calls :-)