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,999932ecc319322a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!newshub.sdsu.edu!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: advice on package design Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.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: <1110212638.336123.298580@l41g2000cwc.googlegroups.com> <1gbk0qx2sgzpg$.sltzfssofla8$.dlg@40tude.net> <1110286121.068133.82160@l41g2000cwc.googlegroups.com> Date: Tue, 8 Mar 2005 18:18:25 +0100 Message-ID: <1czv12sp1pfai.ieuftfegplth$.dlg@40tude.net> NNTP-Posting-Date: 08 Mar 2005 18:18:22 MET NNTP-Posting-Host: bcdd5cfe.newsread2.arcor-online.net X-Trace: DXC=Q8XOjF=Ig\^ghFd\k@b23TQ5U85hF6f;TjW\KbG]kaMXliQbn6H@_EY9:P^?4EWN7_WRXZ37ga[7ZncfD5BXcIXP:P:OkbWkLhW X-Complaints-To: abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:8866 Date: 2005-03-08T18:18:22+01:00 List-Id: On 8 Mar 2005 04:48:41 -0800, spambox@volja.net wrote: > Dmitry A. Kazakov wrote: > >> There are many different ways to deal with that. If you have > > Dmitry, thank you very much for you help; this is the second time that > you've posted elaborate answers to my problems. I apreciate it. You are welcome. >> 2. You can instantiate your Baz outside Foo but with the things >> defined in the public part of Foo: > >> Note that the body of Foo may still use Baz: > > My thoughts on this solution: the package would have to know how the > user chose to instantiate another package, so that it could use the > same name. On the other hand, let's say the package came with > instructions as to how the package it depends on should be > instantiated. Ada also has formal generic packages. If Foo has to be dependent on an instantiated by user Bar, then you can make it generic: generic type Word is ...; with package Baz is new Bar (Word, ...); package Foo is ... end Foo; Though this would inverse the dependency between Foo and Baz. > However, that would leave the user no choice for the name > and effectively we would get something similar to your first solution. > I find this approach better; the package `a' comes with instructions, > directing the user to "use" something that was instantiated in `a' with > the same name, of course. Sure, it could also be renamed later. > >> 3. You can rename parts of contents of Baz in Foo: > > At present, this is the accepted solution. It seems to me that it's > also the most logical for ada? Be careful. Ada community is deeply divided on this issue! (:-)) There are people who depreciate use of use. Sorry for an unintended pun. (:-)) I am not among them. > Since we're forced to follow the rules > of strong typing, then it's only logical to have different subroutines > for each type. There are only less than ten subroutines in my linked > lists package, so renaming then was easy. Besides, the program becomes > clearer (in the end, that's what ada encourages us to do, right?) -- > now, for example, we can use a word_walk subroutine for word lists, and > eg. node_walk for all the others. Agreed, a good idea. Though it is probably not your case, but just to complete the picture... Ada supports implementation through renaming. For example, the following is legal: package Foo is type Word is ... procedure Insert (...); private package Baz is new Bar (Word, ...); -- They won't see it procedure Insert (...) renames Baz.Insert; -- Insert is implemented through renaming of a procedure ... end Foo; This way you can hide the fact of instantiation of Bar and that Insert is implemented in Bar. Unfortunately it does not work with types. There is no type renaming in Ada. Subtyping and deriving a new type sometimes can do the trick, sometimes not. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de