comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Initialize with aggregate?
Date: 22 Nov 2005 15:07:37 -0500
Date: 2005-11-22T15:07:37-05:00	[thread overview]
Message-ID: <wcc4q641m5y.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 1132678643.906071.122770@z14g2000cwz.googlegroups.com

"Adam Beneschan" <adam@irvine.com> 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



      reply	other threads:[~2005-11-22 20:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-21 19:40 Initialize with aggregate? ejijott
2005-11-21 21:38 ` Gautier Write-only
2005-11-21 21:49 ` Simon Wright
2005-11-22 17:10   ` Adam Beneschan
2005-11-22 20:00     ` Simon Wright
2005-11-21 22:21 ` Robert A Duff
2005-11-22 16:57   ` Adam Beneschan
2005-11-22 20:07     ` Robert A Duff [this message]
replies disabled

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