comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: When to use Bounded_String?
Date: Mon, 20 Nov 2017 09:32:39 +0200
Date: 2017-11-20T09:32:39+02:00	[thread overview]
Message-ID: <f7feonFtp9qU1@mid.individual.net> (raw)
In-Reply-To: <outpp0$vp3$1@dont-email.me>

On 17-11-20 07:38 , J-P. Rosen wrote:
> Le 19/11/2017 à 10:55, Niklas Holsti a écrit :
>> On 17-11-19 04:19 , Victor Porton wrote:
>>> What is the main purpose of Bounded_String?
>>
>> As I understand it, the purpose is to let a program use string variables
>> of dynamically varying length, without using dynamically allocated heap
>> memory. The penalty is a fixed upper bound on the length, and perhaps
>> more copying of characters from one variable to another (depending on
>> the implementation).
>>
> No, it's not just a matter of implementation. Bounded_String are a good
> fit for data types implemented as strings. A typical example is name,
> address, etc. from a person's data. These are represented as strings,
> you need variable length,

Yes, but that could be done with Unbounded_String.

> and there is generally a maximum length
> (comming f.e. from the declaration in the underlying database).

It's my impression that fixed length bounds on database fields are 
(happily) going out of fashion, and that the modern database systems 
support (practically) unbounded lengths, as do modern GUI systems.

Anyway, I would not build a DB-imposed field-length limitation into the 
basic data types of the application, but would let the DB/API apply the 
length check. Then, if the DB length bound turns out to be too small in 
practical operation, it is enough to correct the DB definition; the 
application does not need to change.

A limit on the length of a DB entry is only one of many checks that may 
be needed on the entry, such as the allowed character set or other 
lexical and syntactic constraints.

> Note that each instantiation provides a different type, so you cannot
> assign a name to an address.

A side-effect of genericity. Deriving new types from Unbounded_String 
has the same effect, if needed.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


  reply	other threads:[~2017-11-20  7:32 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-19  2:19 When to use Bounded_String? Victor Porton
2017-11-19  9:55 ` Niklas Holsti
2017-11-20  5:38   ` J-P. Rosen
2017-11-20  7:32     ` Niklas Holsti [this message]
2017-11-23 10:04 ` briot.emmanuel
2017-12-28 11:46   ` Vincent DIEMUNSCH
2017-12-28 12:00     ` Dmitry A. Kazakov
2017-12-28 12:29       ` Mehdi Saada
2017-12-29  0:42         ` Randy Brukardt
2017-12-29  9:11         ` Simon Wright
2017-12-28 14:28       ` vincent.diemunsch
2017-12-29  0:36         ` Randy Brukardt
2017-12-29  8:48           ` Dmitry A. Kazakov
replies disabled

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