> 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;
> Result: Matrix(Number_of_Rows, Number_of_Columns) := (others => 0);
> for I in 1..Number_of_Rows loop
> for J in 1..Number_of_Columns loop
> end loop;
> end loop;
> 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 ....
function Get_Matrix return Matrix is
Result: Matrix (1 .. Get ("Rows: "),
1 .. Get ("Columns: "));
for I in Matrix'Range(1) loop
for J in Matrix'Range(2) loop
Get ("Value(" & Integer'Image (I) & ","
Integer'Image (J) & "): " );
return Result; -- don't forget this...
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.