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,ed290afd6f09a679 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newscon06.news.prodigy.com!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Initialize with aggregate? Date: 22 Nov 2005 15:07:37 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1132602018.206322.285630@g44g2000cwa.googlegroups.com> <1132678643.906071.122770@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1132690058 846 192.74.137.71 (22 Nov 2005 20:07:38 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Tue, 22 Nov 2005 20:07:38 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:6533 Date: 2005-11-22T15:07:37-05:00 List-Id: "Adam Beneschan" writes: > > Hardwiring Item'Length to 50 isn't a good idea, and it makes the > > programming harder, because you have to carefully avoid the junk > > at the end. > > I don't see how you can make a blanket statement like this. You're right. Perhaps I should say, "Hardwiring Item'Length to 50 is _almost_never_ a good idea." The way I showed is fine if the string doesn't change its length. If it does, Strings.Unbounded is most likely what you want. In the unlikely event that the length changes, and "50" is an appropriate upper-bound, Strings.Bounded is probably best, as you mention below. A blank-padded string is unlikely to be a good idea. >...If you > code it the way you've shown, you can't change "len" in a node once > you've allocated it. But sometimes changing "item" and "len" in an > existing node to change the length of the string, without changing the > other fields in the node, is what you want to do, so there are cases > where the original poster's implementation is more appropriate than > using a discriminant record. (Using Ada.Strings.Bounded may make > programming easier still, but you still have to hardwire a maximum > length.) - Bob