Article View: net.lang.ada
Article #856Re: Preferred style of use-clauses
From: Larry Wall
Date: Wed, 06 Aug 1986 20:45
Date: Wed, 06 Aug 1986 20:45
52 lines
2936 bytes
2936 bytes
Have you guys actually been burned by USE clauses, or are you just afraid of
the dark?
I can only see two situations where a USE clause might hurt you:
1) If you USE two packages with homographic subprograms, you could end up
relying on overloading. This cannot get you the wrong subprogram unless
you make an *explicit* type error. You cannot get the wrong subprogram
by specifying the type insufficiently--this will only result in ambiguity,
which results in an illegal call, caught at compile time (6.6-3).
2) You CAN get the wrong subprogram by the hiding mechanism. Consider the
following:
with FOO;
procedure BAR is
procedure X is ... end X;
procedure SUBBAR is
use FOO; -- FOO declares procedure X also
begin
X; -- this is BAR.X, not FOO.X
end SUBBAR;
end BAR;
The hiding occurs because directly visible declarations hide within their
immediate scope anything that would be made visible by a USE clause (8.4-5).
It seems to me that mistaking BAR.X for FOO.X is more likely because the USE
clause is so much closer than the declaration of the directly visible BAR.X.
In this case, putting the USE up with the WITH might be less confusing,
especially to someone reading the program backwards to find the declaration
of X.
Neither of these problems is a strong argument against using USE clauses.
#1 is more of an argument against overloading. #2 is an argument against
nesting procedures too deeply.
If you are in a situation where the types of your subprogram arguments are
clear, and your abstract types are all nicely confined to packages so that
you don't rely on hiding mechanisms of dubious value, I see no reason to
avoid the use of multiple USE clauses, even in large projects, even where
it results in overloading. In particular, the use of overloaded operators
in infix notation pretty requires either a USE clause or a slough of RENAMESes.
My rule of thumb would be this: only use USE over large scopes, where the
package used is well known, and can be borne in mind as part of the global
context. In narrow scopes I'd tend to use RENAMES instead, to avoid problems
with hiding.
How's that for being contrary?
Larry Wall
{allegra,burdvax,cbosgd,hplabs,ihnp4,sdcsvax}!sdcrdcf!lwall
Technical Details
Message-ID:
<2938@sdcrdcf.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!lll-crg!seismo!nbires!hao!hplabs!felix!scgvaxd!trwrb!sdcrdcf!lwallReferences:
<860802130119.442853@MIT-MULTICS.ARPA> <8608041746.AA00283@jade.SPP.TRW>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!caip!lll-crg!seismo!nbires!hao!hplabs!felix!scgvaxd!trwrb!sdcrdcf!lwall From: lwall@sdcrdcf.UUCP (Larry Wall) Newsgroups: net.lang.ada Subject: Re: Preferred style of use-clauses Message-ID: <2938@sdcrdcf.UUCP> Date: Wed, 6-Aug-86 16:45:17 EDT Article-I.D.: sdcrdcf.2938 Posted: Wed Aug 6 16:45:17 1986 Date-Received: Sun, 10-Aug-86 20:05:29 EDT References: <860802130119.442853@MIT-MULTICS.ARPA> <8608041746.AA00283@jade.SPP.TRW> Reply-To: lwall@sdcrdcf.UUCP (Larry Wall) Organization: System Development Corporation R&D, Santa Monica Lines: 52