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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border2.nntp.dca1.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!1.eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: "G.B." Newsgroups: comp.lang.ada Subject: Re: {Pre,Post}conditions and side effects Date: Wed, 13 May 2015 13:53:59 +0200 Organization: A noiseless patient Spider Message-ID: References: <2430252d-52a1-4609-acef-684864e6ca0c@googlegroups.com><0a718b39-ebd3-4ab5-912e-f1229679dacc@googlegroups.com><9ee5e186-5aaa-4d07-9490-0f9fdbb5ca18@googlegroups.com><87tww5296f.fsf@adaheads.sparre-andersen.dk><871tj9dp5b.fsf@theworld.com> <87pp6a1u9w.fsf@jester.gateway.sonic.net> <877fsd1xb5.fsf@jester.gateway.sonic.net> Reply-To: nonlegitur@futureapps.de Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Wed, 13 May 2015 11:52:53 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="b96887e80893c84a90c3007226ca0d1c"; logging-data="11817"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mjgpI7Yuqk1KHkfeJiO7MfSzVpIueigc=" User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 In-Reply-To: Cancel-Lock: sha1:gznWzu5cWSNDWGBt4gxwsQrXCHk= Xref: number.nntp.giganews.com comp.lang.ada:193170 Date: 2015-05-13T13:53:59+02:00 List-Id: On 13.05.15 11:35, Dmitry A. Kazakov wrote: > The > proper design is a composite type Sorted_Array with an*invariant* that > ensures the array sorted. This shifts responsibility. Also, why does the array need to be sorted during its entire life time? How do you know that? A contract for Binary_Search could require that (a) input data is any plain old array of numbers (b) in sorted order, by "<=" Why require some fancy abstraction imposed on client code because the supplier feels it to be the proper design, reflecting his particular idea of design for his particular idea of what the job really is, even though it is not his job? What is the difference between - the use of a sorted array (by precondition) in one place and - the use of a sorted array (by invariant) in the very same place, when there is only this place? Binary_Search (It : Num; Data : Ary) with Pre => Is_Sorted (Ary); vs type Sorted_Array is private with Type_Invariant => Is_Sorted (Sorted_Array); Binary_Search (It : Num; Data : Sorted_Ary); Does every single, isolated algorithm on data warrant a corresponding type? There is no context here. So, there is nothing that says that keeping some array-like private composite in sorted order would improve the client's design. If customers should be told how to structure their data so that the contract matches the supplier's design ideas why not require that the client keep an index for the array? Then, the supplier could create his Binary_Search as Search, based on the properties of customer built index... Which, then would get a suitable contract ... I hope the shift in responsibility becomes apparent. Every contract has to start from some reality. How could a design be compared to another without knowing the exact problem?