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,FREEMAIL_FROM autolearn=unavailable autolearn_force=no version=3.4.4 X-Received: by 10.129.146.194 with SMTP id j185mr7373697ywg.26.1447239131757; Wed, 11 Nov 2015 02:52:11 -0800 (PST) X-Received: by 10.182.247.67 with SMTP id yc3mr93851obc.0.1447239131724; Wed, 11 Nov 2015 02:52:11 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer03.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!f78no987040qge.1!news-out.google.com!f6ni948igq.0!nntp.google.com!i2no237524igv.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Wed, 11 Nov 2015 02:52:11 -0800 (PST) In-Reply-To: <87io597447.fsf@theworld.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=109.88.54.35; posting-account=6m7axgkAAADBKh082FfZLdYsJ24CXYi5 NNTP-Posting-Host: 109.88.54.35 References: <7ba56b33-28d4-42d2-8b9b-5ad9f5beab8b@googlegroups.com> <87io597447.fsf@theworld.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <66278720-249a-4191-a908-bb840e7f3ccc@googlegroups.com> Subject: Re: Bounded String question From: Serge Robyns Injection-Date: Wed, 11 Nov 2015 10:52:11 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 3726 X-Received-Body-CRC: 1716885295 Xref: news.eternal-september.org comp.lang.ada:28294 Date: 2015-11-11T02:52:11-08:00 List-Id: Hi Bob, On Wednesday, 11 November 2015 01:48:43 UTC+1, Bob Duff wrote: > How about: >=20 > 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 ex= pose that. I was expecting that the compiler will have more optimization o= ptions with such a construct than a dynamic construct like above. =20 > 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 expre= ss my intent as per my "expectations". Even if I would end up using GNAT i= n all cases. > > Maybe I'm using bounded strings completely wrong. >=20 > Well, I think the Ada.Strings.Bounded package is way overengineered. > So "using Ada.Strings.Bounded" =3D "using bounded strings wrong". ;-) > I suggest rolling your own. No need for generics. >=20 > type Bounded_String (Max_Length : Natural :=3D ...) is limited record > Length : Natural :=3D 0; > Chars : String (1 .. Max_Length); > end record; >=20 > along with a few trivial operations. I tend to agree that the bounded strings seems over-engineered but I'm lack= ing 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 wh= y 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 AP= I 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_St= ring (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 be= lieve in its core principles of allowing developing reliable software. Now with regards to rolling my own, is this not defeating re-use? Why shal= l 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" en= ds up in record types which in the end will map to database entities. > - Bob Serge