Records that could be arrays
- From: Justin Gombos <rpbkbq.xax.gld@xxxxxxxx>
- Date: Thu, 23 Feb 2006 04:11:34 GMT
I noticed this example code in 5.4.4 of the Ada Quality and Style
Guide:
type Coordinate is
record
Row : Local_Float;
Column : Local_Float;
end record;
type Window is
record
Top_Left : Coordinate;
Bottom_Right : Coordinate;
end record;
Would anyone here write something like that?
They are trying to illustrate that records should not always be flat,
which is a fine example for that purpose, but this seems to set a poor
example. Does anyone see a reason to use a record when an array can
be used? My version of the same structure would look more like:
type Axis is (Row, Column);
type Window_Vertex is (Top_Left, Bottom_Right);
type Coordinate is array (Axis) of Local_Float;
type Window is array (Window_Vertex) of Coordinate;
I have set a rule for myself: Composite types composed solely of one
type of element should be declared as arrays rather than records.
I've never seen this rule in a coding standard. The idea is that you
can be more expressive with an array. Example- there are more options
when it comes to an arrays role in control structures. Plus the
"others =>" notation is available. Thoughts?
--
PM instructions: do a C4esar Ciph3r on my address; retain punctuation.
.
- Follow-Ups:
- Re: Records that could be arrays
- From: Stephen Leake
- Re: Records that could be arrays
- From: Jean-Pierre Rosen
- Re: Records that could be arrays
- From: john Doef
- Re: Records that could be arrays
- From: Wilhelm Spickermann
- Re: Records that could be arrays
- From: tmoran
- Re: Records that could be arrays
- Prev by Date: Re: Ada95 skills test - Beta version(FREE)
- Next by Date: Re: Records that could be arrays
- Previous by thread: floating point to fixed point conversion
- Next by thread: Re: Records that could be arrays
- Index(es):