comp.lang.ada
 help / color / mirror / Atom feed
* Records that could be arrays
@ 2006-02-23  4:11 Justin Gombos
  2006-02-23  4:51 ` tmoran
                   ` (4 more replies)
  0 siblings, 5 replies; 23+ messages in thread
From: Justin Gombos @ 2006-02-23  4:11 UTC (permalink / raw)


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.



^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2006-03-01 22:44 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-23  4:11 Records that could be arrays Justin Gombos
2006-02-23  4:51 ` tmoran
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox