-- Demonstrates why globals hinder debugging
-- Parameter list should indicate all communication to and from a routine
-- When searching for an error, should be able to examine only parameter lists
with ada.text_io; use ada.text_io;
with ada.integer_text_io; use ada.integer_text_io;
procedure globals2 is
procedure before(x: natural) is
g1: integer;
begin
g1 := 2 * x;
put(g1);
end before;
gl: integer := 22;
procedure after(x: in out natural) is
gi: integer;
begin
gl := 3 * x;
x := 0;
put(gl);
end after;
n: natural := 3;
begin
put(n); -- 3 - correct
put(gl); -- 22 - correct
before(n);
after(n);
put(n); -- 0 - Assume this is an error. Where did it come from?
put(gl); -- 9 - error - where did that error come from?
-- For n, need only look in after. For g1 must examine entire program.
end globals2;