Ada 95 Quality and Style Guide | Chapter 8 |
8.2.1 Named Numbersguideline
Use named numbers and static expressions to allow multiple dependencies to be linked to a small number of symbols. example
------------------------------------------------------------------------ procedure Disk_Driver is -- In this procedure, a number of important disk parameters are -- linked. Number_Of_Sectors : constant := 4; Number_Of_Tracks : constant := 200; Number_Of_Surfaces : constant := 18; Sector_Capacity : constant := 4_096; Track_Capacity : constant := Number_Of_Sectors * Sector_Capacity; Surface_Capacity : constant := Number_Of_Tracks * Track_Capacity; Disk_Capacity : constant := Number_Of_Surfaces * Surface_Capacity; type Sector_Range is range 1 .. Number_Of_Sectors; type Track_Range is range 1 .. Number_Of_Tracks; type Surface_Range is range 1 .. Number_Of_Surfaces; type Track_Map is array (Sector_Range) of ...; type Surface_Map is array (Track_Range) of Track_Map; type Disk_Map is array (Surface_Range) of Surface_Map; begin -- Disk_Driver ... end Disk_Driver; ------------------------------------------------------------------------rationale
To reuse software that uses named numbers and static expressions appropriately, just one or a small number of constants need to be reset, and all declarations and associated code are changed automatically. Apart from easing reuse, this reduces the number of opportunities for error and documents the meanings of the types and constants without using error-prone comments.
< Previous Page | Search | Contents | Index | Next Page > |
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC | TOC |
Appendix | References | Bibliography |