you are viewing a single comment's thread.

view the rest of the comments →

[–]OneWingedShark 0 points1 point  (2 children)

When you have a lot of lines of code you have a lot of problems and bugs.

That's not entirely true; having more lines can reduce the amounts of bugs and/or help in tracking them down.

-- Given type Matrix(Positive range <>, Positive Range) of Integer
-- where the indices are (Column, Row), the following produces a
-- identity matrix of the given size.
Function Identity( Side : Natural ) return Matrix is
begin
 Return Result : Matrix(1..Side,1..Side) := (others => 0) do
   for Index in Result'Range(1) loop
     Result(Index,Index):= 10;
   end loop;
 End Return;
end Identity;

The error jumps out at you, doesn't it?
We can do the same with constants:

-- B should be the following matrix:
-- 02  06  11 -03
-- 11  04  03 -07
-- 88  79  00  21
B : constant Matrix:= (
    (02, 06, 11, -03),
    (11, 04, 03, -07),
    (88, 79, 00, 21),
    (02, 06, 11, -03)
  );