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 X-Received: by 10.236.14.99 with SMTP id c63mr7654765yhc.40.1406313659257; Fri, 25 Jul 2014 11:40:59 -0700 (PDT) X-Received: by 10.182.130.131 with SMTP id oe3mr17480obb.26.1406313658807; Fri, 25 Jul 2014 11:40:58 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!peer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!v10no2515054qac.1!news-out.google.com!eg1ni5igc.0!nntp.google.com!h18no4388019igc.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 25 Jul 2014 11:40:58 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.57.209.48; posting-account=zwxLlwoAAAChLBU7oraRzNDnqQYkYbpo NNTP-Posting-Host: 173.57.209.48 References: <1xeciz1z2smla$.lxa15ypfbre9$.dlg@40tude.net> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <3e94fe4f-c9f4-41dd-95e7-a0e329a2ef48@googlegroups.com> Subject: Re: Effective use of derived types From: "Dan'l Miller" Injection-Date: Fri, 25 Jul 2014 18:40:59 +0000 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Received-Bytes: 4829 X-Received-Body-CRC: 3531566615 Xref: news.eternal-september.org comp.lang.ada:21219 Date: 2014-07-25T11:40:58-07:00 List-Id: On Friday, July 25, 2014 1:00:06 PM UTC-5, Victor Porton wrote: > Dmitry A. Kazakov wrote: > > On Fri, 25 Jul 2014 19:40:27 +0300, Victor Porton wrote: > >> I write an Ada library (in fact thick bindings to a C library), which > >> (among other) deals with some strings, including URIs. > >> Should I introduce new type for URI strings? >=20 > > Yes. >=20 > >> type URI_String is new String; >=20 > > No. >=20 > > URI is not a string. It has a textual representation, which is a string > > (one of many types of strings). If you want a type for URI it should ke= ep > > its fields. You will have functions alike to attributes Value and Image= to > > convert URI from and to String. Dmitry, at some shallow level your statements are trivially correct, but ar= e quite misleading as stated if taken to heart deeply. Victor is not askin= g whether URI should be a tagged record; of course it should. Victor is no= t asking whether that URI tagged record should have its package associated = functions taking the URI tagged record as their first parameter; of course = it should. Instead, Victor is asking whether the URI_string member of the = URI tagged record (and return/out-bound value of dispatched functions & pro= cedures thereof) should be a subtype of string or not. I say of course URI should be a subtype of string in Ada2012 so that it can= Dynamic_Predicate post-conditions that enforce the regular expression that= URIs must obey. A(t least one) function that takes the URI tagged record = as its first parameter should return that constant URI_string subtype (not = general Ada.string) so that app-domain code that uses Victor's URI tagged r= ecord is informed of these regular-expression restrictions. Perhaps the bigger question is: would the URI'Class include URL and URN? = If so, would the URL and URN tagged records have URL_string and URN_string = subtypes of URI_string? How would overriding URL's dispatched function & p= rocedures interact with the desire to use the narrower URL_string and URN_s= tring in those URL & URN contexts instead of the (a-little-too-permissive-)= URI_string. Using too-permissive-URI_string is nearly as bad as using the = vastly-too-permissive-Ada.string. A good design will hinge on the proper f= inessing of these URL and URN finer points. Btw, even more so when one con= siders the vast variety of URNs & their respective syntaxes (e.g., ISBNs, = IETF RFC, ASN.1 OID) > I am writing thick Ada bindings to a C library which has URI objects. >=20 > But the C implementation of URI sometimes uses strings (say to initialize= a=20 > new URI object from a string). >=20 > So my question remains in force. Good for you, Victor. I would add that the lesson here is that as a designer you should ask yours= elf: does this thing A-prime have a fundamentally different nature (to the= beast) than similar thing A? For example where Ada.string is thing A and = URI_string is thing A-prime, does string have the ability to contain a diff= erent character-set than URI_string (or the same character-set but with esc= aping mechanism to partition the valuespace)? Ada.string can contain an ar= bitrary quantity of whitespace, whereas URI_string cannot have spaces in do= main-names of URLs nor to the left of the // in the protocol prefix. Hence= , that whitespace prohibition goes into the Dynamic_Predicate post-conditio= n of URI_string's declaration of subtype of Ada.string. Likewise, for all = the other regular-expression characteristics that narrow URI_string from ge= neral-purpose Ada.string.