From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ffc9e2fe760c58fd X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newspeer.monmouth.com!nntp.abs.net!news.abs.net!not-for-mail Newsgroups: comp.lang.ada Subject: Re: Records that could be arrays References: From: Stephen Leake Message-ID: User-Agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (windows-nt) Cancel-Lock: sha1:ZevE2akLdY3JcJ4aXAJZGecM+7M= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Thu, 23 Feb 2006 08:06:18 -0500 NNTP-Posting-Host: 66.159.65.1 X-Complaints-To: abuse@toad.net X-Trace: news.abs.net 1140699986 66.159.65.1 (Thu, 23 Feb 2006 08:06:26 EST) NNTP-Posting-Date: Thu, 23 Feb 2006 08:06:26 EST Xref: g2news1.google.com comp.lang.ada:3100 Date: 2006-02-23T08:06:18-05:00 List-Id: Justin Gombos writes: > 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? Yes; Windex has it. Although if I was rewriting it from scratch now, I might use an array. > 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? I usually lean towards arrays, partly for the reasons you give, partly because I have library utilities that work much more nicely with arrays than records; Text_IO and containers for example. I can create a Text_IO procedure Put for an array with a simple instantiation; for a record, I have to use auto_text_io. But records are deeply embedded in my psyche; these types just feel more natural as records than arrays. I guess we need to catch the kids in high school, and teach them to use arrays instead of records. -- -- Stephe