From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=BAYES_00,XPRIO autolearn=no autolearn_force=no version=3.4.6 Path: eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: use clauses Date: Tue, 12 Apr 2022 20:05:00 -0500 Organization: A noiseless patient Spider Message-ID: References: <607b56f8$0$3721$426a34cc@news.free.fr> <607bf826$0$3733$426a74cc@news.free.fr> <86im4hj6eh.fsf@stephe-leake.org> <827fce15-8277-4ec8-a627-01158b42a191n@googlegroups.com> <4205785c-6818-4e26-b931-5a775e2c426cn@googlegroups.com> <62560a6b$0$18724$426a74cc@news.free.fr> Injection-Date: Wed, 13 Apr 2022 01:05:02 -0000 (UTC) Injection-Info: reader02.eternal-september.org; posting-host="a863a4ac0777e526b7dfd040fe710118"; logging-data="31991"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZqpJotDm+Z5W5q4qIBrqUTx/reVZt4kU=" Cancel-Lock: sha1:cSZs144YRTIQF+2IUjPfBv2Vleg= X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.7246 X-RFC2646: Format=Flowed; Original X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-Priority: 3 X-MSMail-Priority: Normal Xref: reader02.eternal-september.org comp.lang.ada:63736 List-Id: "Thomas" wrote in message news:62560a6b$0$18724$426a74cc@news.free.fr... > In article , > "Randy Brukardt" wrote: > >> For me, a naming scheme that discourages the use of (package) use clauses >> is >> a bonus. (Such a scheme makes it easier to avoid use clauses.) > > I agree to avoid use clauses. > > (I personally prefer Lists.List, like Vincent Marciante - > i like Ada.Containers.* naming :-) ) > > >> I personally >> only use "use type" in new code (there's tons of old code for which that >> doesn't work, of course, but that doesn't change the principle). > > what do you think about: > - "use all type" clauses? This is OK; I don't use them mainly because I only use features implemented in Janus/Ada, and "use all type" is not yet implemented there. The fundamental problem with "use" is that it makes everything visible, and then deals with conflicts by making those things invisible again. That's not problem for overloadable primitive operations, since the profile is included and conflicts only occur when someone has made a lousy design choice (creating a routine with the same name and profile as a primitive) [Most such conflicts come from maintenance when some existing routine is moved to be primitive; in such cases, the original routine simply should be removed.] Since "use all type" only works on overloadable primitives (and things that work rather like primitives), it's fairly safe. One could make an argument that primitive operations should always be visible when the type is (that's not the Ada rule, but argubly it would work better in most circumstances) -- and you should always know to look at primitives anyway when trying to find something.. > - List.Clear? (could you remember me how you call that, please?) For tagged types, you can use prefix notation, so "My_List.Clear" is the easiest. With "use all type List", you can write Clear(My_List). If your objects have well-choosen names, it's not really needed to have the type around for such operations, even when use clauses are in place. Thus, "Clear", not "Clear_List", and that works well even when someone uses everything in sight (of course, they may have a hard time finding where Clear is defined when debugging, but that's their choice). > - List.Clear does work only if List is tagged? Right. There are a number of semantic issues for untagged types, the main ones having to do with implicit dereference (which occurs in this notation, as in any other selected_component notation). If you have a prefix of an access type, it gets very messy to determine which dereference is which. And just allowing composite types doesn't work well either: a private type that is completed with an access type would *lose* operations when it had full visibility -- that seems pretty weird. It originally got limited to tagged types as that was easy to do and didn't have semantic issues. We were going to look at generalizing the prefix notation again (several people asked about it), but no one made a concrete proposal and it never went anywhere for Ada 2022. Randy.