TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Condense Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Sender:
"Team Ada: Ada Advocacy Issues (83 & 95)" <[log in to unmask]>
Subject:
From:
"W. Wesley Groleau x4923" <[log in to unmask]>
Date:
Thu, 10 Dec 1998 16:16:59 -0500
Reply-To:
"W. Wesley Groleau x4923" <[log in to unmask]>
Parts/Attachments:
text/plain (64 lines)
>      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
> easier.

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
below.

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

      -- Load_Car
      for I in 1 .. 100 loop  -- Why do people find 'Range so hard to use?
        Put (Suitcase(I), Car);
        if -- no more suitcases
        then
          exit;  -- same question for exit when...
        end if;
      end loop;
      -- 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)
      -- Over_The_River
      (ten more SLOC)
      -- Through_The_Woods
      (twenty SLOC, every other one being Check For and Avoid_Wolf)
      Stop_At_Gas_Station
      (forty SLOC, including if's nested five deep to select the gas station)
      -- Lecture_Kids_About Manners
      Topic := Manners;
      (five SLOC)
      -- 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 :-)

end Trip;

ATOM RSS1 RSS2