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!feeder.eternal-september.org!aioe.org!.POSTED.N5M2DXr2fJIsm61cKlUWUQ.user.gioia.aioe.org!not-for-mail From: Simon Wright Newsgroups: comp.lang.ada Subject: Re: gnat.string_split , howto manipulate slice numbers Date: Wed, 30 Oct 2019 11:30:55 +0000 Organization: Aioe.org NNTP Server Message-ID: References: <5d710dac-d172-4a31-899e-1bf95e220ed6@googlegroups.com> <7fb6d1d0-18df-43b9-bcdc-9782dfb5171c@googlegroups.com> NNTP-Posting-Host: N5M2DXr2fJIsm61cKlUWUQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (darwin) X-Notice: Filtered by postfilter v. 0.9.2 Cancel-Lock: sha1:QTfPmQ2tAtrbsMM2LoTYLCO2kKY= Xref: reader01.eternal-september.org comp.lang.ada:57387 Date: 2019-10-30T11:30:55+00:00 List-Id: "Dmitry A. Kazakov" writes: > On 2019-10-29 19:33, J-P. Rosen wrote: >> Le 29/10/2019 à 17:47, Simon Wright a écrit : >>> type Slice_Number is new Natural; >>> >>> For me, this carries declaring a type rather than a subtype further than >>> necessary. A subtype? Or why not just use Natural? >> Integer (or its subtypes) should be avoided in general. It is non >> portable, and carries no information to the reader about the purpose of >> the type. Making appropriate types that cannot be mixed is key to the >> philosophy of Ada ("strong typing", you know...). > > Another reason is to distinguish index/key from position. When both > are subtypes of integer some bugs may slip through, e.g. > > A (A'Length - 1) > > This is broken code, but the compiler cannot detect it. How is it broken? > Or when you instantiate a generic container: > > generic > type Position_Type is range <>; > type Index_Type is private; > type Element_Type is private; > package Generic_Container is > ... > function Get (Container : Container_Type; Position : Position_Type) > return Element_Type; > function Get (Container : Container_Type; Key : Key_Type) > return Element_Type; > > It fails when instantiated with subtypes of same integer type. Again.You'd need to use named parameter association, but otherwise, what am I missing?