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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: When to use Bounded_String? Date: Mon, 20 Nov 2017 09:32:39 +0200 Organization: Tidorum Ltd Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net K2V7bMZka2PIzMCtHkH88Qnx5SN5rQS1ok6fL2PB5dGeOeRPQJ Cancel-Lock: sha1:XSDMWlDt1f57PAIOK+a6J6t2plg= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: Xref: feeder.eternal-september.org comp.lang.ada:49012 Date: 2017-11-20T09:32:39+02:00 List-Id: 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 . @ .