From: tmoran@acm.org
Subject: Re: Records that could be arrays
Date: Wed, 22 Feb 2006 22:51:57 -0600
Date: 2006-02-22T22:51:57-06:00 [thread overview]
Message-ID: <N66dnZoT4LzwomDeRVn-sQ@comcast.com> (raw)
In-Reply-To: WBaLf.18619$HU.13588@trnddc04
> type Coordinate is
> record
> Row : Local_Float;
> Column : Local_Float;
> end record;
In mathematics, one usually gives a coordinate as (x,y), while in
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.
next prev parent reply other threads:[~2006-02-23 4:51 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-23 4:11 Records that could be arrays Justin Gombos
2006-02-23 4:51 ` tmoran [this message]
2006-02-23 13:19 ` Justin Gombos
2006-02-24 10:19 ` Stephen Leake
2006-02-23 6:32 ` Wilhelm Spickermann
2006-02-23 13:08 ` Stephen Leake
2006-02-23 13:20 ` Justin Gombos
2006-02-23 14:29 ` Wilhelm Spickermann
2006-02-24 10:31 ` Stephen Leake
2006-02-26 22:34 ` Wilhelm Spickermann
2006-02-23 8:21 ` john Doef
2006-02-23 9:22 ` Jean-Pierre Rosen
2006-02-23 13:11 ` Stephen Leake
2006-02-23 13:37 ` Justin Gombos
2006-02-23 13:06 ` Stephen Leake
2006-02-23 20:23 ` Simon Wright
2006-02-24 21:23 ` Randy Brukardt
2006-02-25 11:39 ` Dmitry A. Kazakov
2006-02-26 3:24 ` Steve Whalen
2006-02-26 9:51 ` Dmitry A. Kazakov
2006-02-27 2:26 ` Steve Whalen
2006-02-27 9:33 ` Dmitry A. Kazakov
2006-03-01 22:44 ` Robert A Duff
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox