Re: Records that could be arrays
- From: tmoran@xxxxxxx
- Date: Wed, 22 Feb 2006 22:51:57 -0600
type Coordinate isIn mathematics, one usually gives a coordinate as (x,y), while in
record
Row : Local_Float;
Column : Local_Float;
end record;
graphics it's often (vertical, horizontal). Inadvertently switching
the order can be an annoying bug. But with
type Rows is new Local_Float;
type Cols is new Local_Float;
the compiler's type checking can point out such errors. In that case,
of course, you have to use a record with
Row : Rows;
Column : Cols;
and cannot use an array.
If your code might one day have to accomodate 3-D coordinates, then
for A in Axis loop
Sum := Sum + V(A)**2;
needs no change, while
Sum := V.Row**2 + V.Column**2;
will need a makeover, and thus is much less desirable.
The general point is that sometimes an array fits the problem better
and sometimes a record fits it better. A rule that says "hey, they're all
Local_Float so it should be an array" is much too limiting.
.
- Follow-Ups:
- Re: Records that could be arrays
- From: Justin Gombos
- Re: Records that could be arrays
- References:
- Records that could be arrays
- From: Justin Gombos
- Records that could be arrays
- Prev by Date: Records that could be arrays
- Next by Date: Re: Quick question about Ada code formatting.
- Previous by thread: Records that could be arrays
- Next by thread: Re: Records that could be arrays
- Index(es):