I understand one of the big deals about constants is that you don\'t have to go through and update code where that constant is used all over the place. Thats great, but let\'s s
Marking a variable as constant declares your intent as a programmer that this will be a consistent value whenever it's accessed during the execution of the code. Consider it a form of documentation that also causes the compiler to enfore your design.
This isn't really an Ada-specific question.
The general benifits of constants over variables:
Ada specific benifits:
Example:
Seconds_Per_Minute : constant := 60;
Secs_Per_Min : Integer := 60;
type Seconds_Offset is 0 .. Integer'last; --'
Min1, Secs1 : Integer;
Min2, Secs2 : Seconds_Offset;
...
--// Using the named number, both of these compile no problem.
Secs1 := Min1 * Seconds_Per_Minute;
Secs2 := Min2 * Seconds_Per_Minute;
--// The second line here gives an error, since Integer is a
--// different type than Seconds_Offset.
Secs1 := Min1 * Secs_Per_Min;
Secs2 := Min2 * Secs_Per_Min;