comp.lang.ada
 help / color / mirror / Atom feed
From: Serge Robyns <serge.robyns@gmail.com>
Subject: Re: Bounded String question
Date: Wed, 11 Nov 2015 02:52:11 -0800 (PST)
Date: 2015-11-11T02:52:11-08:00	[thread overview]
Message-ID: <66278720-249a-4191-a908-bb840e7f3ccc@googlegroups.com> (raw)
In-Reply-To: <87io597447.fsf@theworld.com>

Hi Bob,

On Wednesday, 11 November 2015 01:48:43 UTC+1, Bob Duff  wrote:
> How about:
> 
>    function No_Client_Name return T_Client_Name is
>       (T_Client_Name (P_Strings.Null_Bounded_String));

May idea was to have a "constant" and use language construct/semantic to expose that.  I was expecting that the compiler will have more optimization options with such a construct than a dynamic construct like above.
 
> But why do you need Preelaborate?  It's not all that much use if you use
> GNAT's static elaboration model.

Just for the sake of "cleanness" and again using language features to express my intent as per my "expectations".  Even if I would end up using GNAT in all cases.

> > Maybe I'm using bounded strings completely wrong.
> 
> Well, I think the Ada.Strings.Bounded package is way overengineered.
> So "using Ada.Strings.Bounded" = "using bounded strings wrong".  ;-)
> I suggest rolling your own.  No need for generics.
> 
>    type Bounded_String (Max_Length : Natural := ...) is limited record
>       Length : Natural := 0;
>       Chars  : String (1 .. Max_Length);
>    end record;
> 
> along with a few trivial operations.

I tend to agree that the bounded strings seems over-engineered but I'm lacking Ada experience to judge that properly.  However it is indeed a pain to use compared to other languages where I come from, e.g. C.  I don't know why strings are so complex to use in Ada. At various places I've conversions between bounded strings and plain strings in order to offer a consistent API to my modules. Luckily the package already provide a To_String function.  However, I've had to write loads of functions like "To_Client_Name (Name : in String) return T_Client_Name is (T_Client_Name (P_Strings.To_Bounded_String (Name));" as I haven't found a more direct way to convert a string to the type. This with some other oddities in Ada is what do give me a lot of frustrations.  However, I do remain decided to proceed with Ada, as I do believe in its core principles of allowing developing reliable software.

Now with regards to rolling my own, is this not defeating re-use?  Why shall I waste my time on such a feature while I'm having loads of things to do on the application itself.

I've been considering using unbounded strings instead but then I'm dropping the idea of a bounded storage for my entities.  Most of these "strings" ends up in record types which in the end will map to database entities.

> - Bob

Serge

  parent reply	other threads:[~2015-11-11 10:52 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-10 22:00 Bounded String question Serge Robyns
2015-11-11  0:48 ` Bob Duff
2015-11-11  2:01   ` Jeffrey R. Carter
2015-11-11 15:34     ` Bob Duff
2015-11-11 17:36       ` Jeffrey R. Carter
2015-11-11 19:22         ` Bob Duff
2016-03-06 18:59       ` Xavier Petit
2016-03-07 23:16         ` Randy Brukardt
2016-03-08  0:08           ` Jeffrey R. Carter
2016-03-09  1:18             ` Randy Brukardt
2015-11-11 10:52   ` Serge Robyns [this message]
2015-11-11 13:43     ` Serge Robyns
2015-11-11 14:32       ` brbarkstrom
2015-11-11 16:08         ` Serge Robyns
2015-11-11 17:27       ` Jeffrey R. Carter
2015-11-11 20:06         ` Serge Robyns
2015-11-11 20:23           ` AdaMagica
2015-11-11 20:27             ` AdaMagica
2015-11-11 20:32             ` Serge Robyns
2015-11-11 20:40               ` AdaMagica
2015-11-12 17:31                 ` Serge Robyns
2015-11-12 19:10                   ` AdaMagica
2015-11-12 21:29                     ` Randy Brukardt
2015-11-12 18:03                 ` G.B.
2015-11-12 18:13                   ` Serge Robyns
2015-11-12 18:14                     ` Serge Robyns
2015-11-12 19:37                   ` Randy Brukardt
2015-11-11 20:42           ` Jeffrey R. Carter
2015-11-12 16:59             ` Serge Robyns
2015-11-12 18:39               ` Jeffrey R. Carter
2015-11-12 21:19                 ` Randy Brukardt
2015-11-12 21:27               ` Randy Brukardt
2015-11-12 22:32                 ` Jeffrey R. Carter
2015-11-13  0:07                   ` Randy Brukardt
2015-11-13  1:01                     ` Jeffrey R. Carter
2015-11-11 15:41     ` Bob Duff
replies disabled

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