TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show HTML 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:
Mon, 14 Dec 1998 11:02:50 -0500
Reply-To:
"W. Wesley Groleau x4923" <[log in to unmask]>
Parts/Attachments:
text/plain (57 lines)
>     The nesting issue really involves nested variable declarations.
> Sometimes variables do need to be nested:
>
>     with Ada.Text_IO;...
>     function Get_Matrix return Matrix is
>       Number_of_Rows, Number_of_Columns: Integer;
>       ...
>     begin
>       Get(Number_of_Rows);
>       Get(Number_of_Columns);
>       declare
>          Result: Matrix(Number_of_Rows, Number_of_Columns) := (others => 0);
>       begin
>          for I in 1..Number_of_Rows loop
>            for J in 1..Number_of_Columns loop
>              Get(Result(I,J));
>            end loop;
>          end loop;
>       end;
>     end Get_Matrix;
>
>     But, and this is the key, such nesting almost always involves delcare
> blocks, not subprograms, or not just subprograms.

On the other hand, Get could be a function....

     function Get (Prompt : String := "") return Integer is ....

     with Ada.Text_IO;...
     function Get_Matrix return Matrix is

       Result: Matrix (1 .. Get ("Rows:    "),
                       1 .. Get ("Columns: "));

     begin

       for I in Matrix'Range(1) loop
         for J in Matrix'Range(2) loop

           Result(I,J) :=
                Get ("Value(" & Integer'Image (I) & ","
                                Integer'Image (J) & "): " );
         end loop;
       end loop;

       return Result;  -- don't forget this...

     end Get_Matrix;

And some of that input could easily be "lifted" to

   function Get_Matrix ( Rows, Columns : Integer ) return ....

I find declare blocks valuable aids to localization, information hiding,
and sometimes for readability.  However, if they are unnecessary, they can
act as "clutter," obscuring more important stuff.

ATOM RSS1 RSS2