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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!mx05.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Seeking for papers about tagged types vs access to subprograms Date: Mon, 13 May 2013 09:22:24 +0200 Organization: cbb software GmbH Message-ID: <1y21fg5hvajvd.1femngelic1xp.dlg@40tude.net> References: <19lrzzbgm77v6.1dzpgqckptaj6.dlg@40tude.net> <1bfhq7jo34xpi.p8n2vq6yjsea.dlg@40tude.net> <12gn9wvv1gwfk.10ikfju4rzmnj.dlg@40tude.net> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: FbOMkhMtVLVmu7IwBnt1tw.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:15535 Date: 2013-05-13T09:22:24+02:00 List-Id: On Mon, 13 May 2013 08:21:14 +0300, Niklas Holsti wrote: > The point of the example was to illustrate typestate analysis. For this > example, with only Open - (Read/Write)* - Close, your approach collapses > the example into a trivial one, where adherence to the operation > protocol is ensured by the necessity to declare a File_Info object > before it can be used. So it would no longer be a useful example. It is still a useful example of a good software component design. > Your approach works in some cases, but it is problematic if you cannot > initialize the object to an "active" state in its declaration, for > example because the "activation" is conditional in some way, or must be > delayed. This is rather a language problem. Most of such cases can be attributed to the lack or insufficient constructors. The notorious Ada's problem with task components is due to the lack of class-wide constructors, when Initialize tries to sit on two chairs struggling to be both a specific and a class-wide initialization. > The "activation" must then be done in a statement, and the > declaration leaves the object in some inactive initial state. That is not a problem so long this state is not exposed. The idea is that when you have an object which may transit from state to state (e.g. a connection object, when the connection can be lost), you should not expose this state. You better make the object to maintain the state (e.g. by making the connection restored by the object automatically) and leave its interface free of the state (e.g. an operation on unconnected object would block or else raise Busy_Error etc). [ Note that here again, the precondition is relaxed to true and the operation behavior gets defined for the exceptional state, which cannot be avoided anyway. ] > Another limitation in your approach is that the opening and closing of > different files must be strictly nested: if you declare and open file A, > then declare and open file B, file B must be closed before file A is > closed (as long as it all happens in the same task). Such forced > constraints between the states of different object is often not wanted. You can have a container, e.g. a bag, to handle this. Jeffrey's model translates this into the problem of object's scope (lifetime), which saves time and mental efforts. Each programmer faces it on daily basis and has his ready-to-use solutions already. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de