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 X-Google-Thread: 103376,5c89acd494ea9116 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news.glorb.com!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Self pointer in limited record Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1183577468.034566.57830@n60g2000hse.googlegroups.com> <46d972e8$0$30384$9b4e6d93@newsspool4.arcor-online.net> <1alyfwaig93sk$.99oy269uon$.dlg@40tude.net> <46d9c138$0$4531$9b4e6d93@newsspool3.arcor-online.net> <1rt8kdcrj6tf.1qgvycc6vh357$.dlg@40tude.net> <46db2bf4$0$7699$9b4e6d93@newsspool2.arcor-online.net> <1188816674.2630.25.camel@kartoffel.vocalweb.de> <9cdmw7k85sey.85sb2t1bjefy$.dlg@40tude.net> <1mbajw59c3eir.jyl8bdp6qvj8.dlg@40tude.net> <1188850449.2630.60.camel@kartoffel.vocalweb.de> <1aza6nzawgcnm.sf76q4dvzw4n$.dlg@40tude.net> <46de8897$0$16115$9b4e6d93@newsspool1.arcor-online.net> <15hzyyy3soem0.12hn79bwy27zt$.dlg@40tude.net> <1189017071.2630.246.camel@kartoffel.vocalweb.de> <46df20aa$0$30370$9b4e6d93@newsspool4.arcor-online.net> <1rio4ocsymy4p$.5u8nabi3tmoq$.dlg@40tude.net> <1189074405.2630.257.camel@kartoffel.vocalweb.de> Date: Thu, 6 Sep 2007 14:25:50 +0200 Message-ID: <13vaef9aa6hn8$.13mrgusdn917m.dlg@40tude.net> NNTP-Posting-Date: 06 Sep 2007 14:25:18 CEST NNTP-Posting-Host: a0693da7.newsspool2.arcor-online.net X-Trace: DXC=lG:5EMjAk4R\PS5Xo=M[RVA9EHlD;3YcR4Fo<]lROoRQ<`=YMgDjhgR6VSnhTQTBJU[6LHn;2LCV^[ On Thu, 06 Sep 2007 12:26:45 +0200, Georg Bauhaus wrote: > On Thu, 2007-09-06 at 09:37 +0200, Dmitry A. Kazakov wrote: >> On Wed, 05 Sep 2007 23:38:34 +0200, Georg Bauhaus wrote: >> >>> They can avoid surprises and nasty issues because they enforce body >>> visibility of data objects. Example: >>> >>> >>> >>> package S is >>> type T is limited private; >>> procedure op(x: in out T); >>> private >>> type T is limited record >>> null; >>> end record; >>> end S; >> >> This is IMO bad design, it should be: >> >> package S is -- Stateless >> type T is limited private; >> ... >> end S; > > IIUC, this will still allow referencing S.T elsewhere. > And even when S has only subprograms, they are visible to > other parts of the program. > But S was intended to be used by some procedure, > and only by the procedure. If you are paranoid about treacherous intentions of your colleges, then make S a private child: private package Data.S is type T(<>) is limited private; ... end Data.S; >> package Data is -- Stateful >> ... -- Operations having an instance of T as a hidden parameter >> end Data; >> >> with S; >> package body Data is >> Singleton : S.T; >> ... >> end Data; >> >> There is no need to "with" S for anybody else, > > Do you think that "No need to with S" will convince programmers > to not touch it? Yes, I do hope they would not do it if I'd ask them, as well as many other things one could do being inspired by the things declared in System, Ada.Unchecked_xxx etc. > When I need to make sure that S is not going > to be used elsewhere, it needs to be hidden. What are the options? Safe and consistent design. Consider what is T in your model? Why there has to be only one instance of? Which meaning has this in terms of the operations on T? Who knows, you might come to a conclusion that this constraint is not really necessary or maybe that it is enforced automatically when T is properly used. In real-life designs there are usually far more access levels than just public/private/body with fuzzy boundaries between them. You have to rely on your design and good will of people working with you. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de