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.3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: gnat.string_split , howto manipulate slice numbers Date: Tue, 29 Oct 2019 20:37:15 +0100 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: 3d73Ybk3C5U4I2t8lv+lAQ.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 Content-Language: en-US X-Notice: Filtered by postfilter v. 0.9.2 Xref: reader01.eternal-september.org comp.lang.ada:57380 Date: 2019-10-29T20:37:15+01:00 List-Id: 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. 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. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de