comp.lang.ada
 help / color / mirror / Atom feed
* Safe "use" directive
@ 2002-11-08 11:53 Victor Porton
  2002-11-08 17:18 ` Peter Richtmyer
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Victor Porton @ 2002-11-08 11:53 UTC (permalink / raw)


I am willing to follow the following coding standard (in almost all
cases) to improve code safety (I consider it a good coding style for
everybody who uses "use"):

Use "use X" directive for a package X only if the package meets the
following criteria:

The visible part of the package X declares nothing except of subtypes,
(generic) subrountines dependent on types declared in visible part of
X, and also (generic) subpackages (recursively) of X contain only
subtypes dependent on types declared in visible part of X and
subrountines dependent on types declared in visible part of X.

This avoids the danger of initentedly "use"ing a subrountine from
one package working on a type from an other package instead of
assumed the-same-named subrountine from the second package.

Do you agree that it is a good rule? (Don't say: never use "use",
I am only about the case if one uses "use".)

Can the current Ada stylistics checking tools enforce such a rule
without too much effort?

P.S. For packages not following this rule (e.g. some Ada.*), it is
possible to create wrapper packages following the rule.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Safe "use" directive
  2002-11-08 11:53 Victor Porton
@ 2002-11-08 17:18 ` Peter Richtmyer
  2002-11-09 10:36 ` Gautier
  2002-11-11 14:44 ` Ted Dennison
  2 siblings, 0 replies; 6+ messages in thread
From: Peter Richtmyer @ 2002-11-08 17:18 UTC (permalink / raw)


porton@ex-code.com (Victor Porton) wrote in message news:<3dcba716$0$305$bed64819@news.gradwell.net>...
> 
> Do you agree that it is a good rule?
>
I like it - or something very much like it that is easy enough
for coders to understand  :-)

Perhaps one "weakness" is that someone may later change the pkg that is
"use'd", so the rule is violated, but not know the effects.
 
> Can the current Ada stylistics checking tools enforce such a rule
> without too much effort?

I don't know. Are there any good and *free* Ada stylistics checking 
tools available?  Anybody?

thanks,
Peter



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Safe "use" directive
  2002-11-08 11:53 Victor Porton
  2002-11-08 17:18 ` Peter Richtmyer
@ 2002-11-09 10:36 ` Gautier
  2002-11-11 14:44 ` Ted Dennison
  2 siblings, 0 replies; 6+ messages in thread
From: Gautier @ 2002-11-09 10:36 UTC (permalink / raw)


Victor Porton:

...
> This avoids the danger of initentedly "use"ing a subrountine from
> one package working on a type from an other package instead of
> assumed the-same-named subrountine from the second package.

Too complicated, I think. The solution is to "use" both packages,
the compiler must then detect ambiguities:

with Text_IO;                           use Text_IO;
with Dual_IO;                           use Dual_IO;

procedure Test_Use is
begin
  New_Line;
end Test_Use;

* ObjectAda:
test_use.adb: Error: line 6 col 3 LRM:8.6(31), Ambiguous call,
possible definitions of New_Line appear at line 92 of file
ada.text_io.spc, line 58 of file dual_io.ads.

* GNAT:
test_use.adb:6:03: ambiguous expression (cannot resolve "New_Line")
test_use.adb:6:03: possible interpretation at dual_io.ads:58
test_use.adb:6:03: possible interpretation at a-textio.ads:169
________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: For a direct answer, address on the Web site!



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Safe "use" directive
  2002-11-08 11:53 Victor Porton
  2002-11-08 17:18 ` Peter Richtmyer
  2002-11-09 10:36 ` Gautier
@ 2002-11-11 14:44 ` Ted Dennison
  2 siblings, 0 replies; 6+ messages in thread
From: Ted Dennison @ 2002-11-11 14:44 UTC (permalink / raw)


porton@ex-code.com (Victor Porton) wrote in message news:<3dcba716$0$305$bed64819@news.gradwell.net>...
> Use "use X" directive for a package X only if the package meets the
> following criteria:

(5 line sentence deleted)

> P.S. For packages not following this rule (e.g. some Ada.*), it is
> possible to create wrapper packages following the rule.

%-(

Wouldn't it be far simpler to just not do the "use"?

> Do you agree that it is a good rule? (Don't say: never use "use",
> I am only about the case if one uses "use".)

Sorry, but I don't agree. Once you let in the possibility that there
could be "use"s clouding things, then when something is going wrong
the maintainer *has* to go check all those other packages. He can't
count on the non-compiler enforced parts of the rules having been
followed (after all, *something* is wrong somewhere, or there wouldn't
be a problem). I'd say this is marginally better than putting no
restrictions on uses, but just marginally.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Safe "use" directive
@ 2002-11-12 22:03 Gautier direct_replies_not_read
  2002-11-18  1:57 ` Richard Riehle
  0 siblings, 1 reply; 6+ messages in thread
From: Gautier direct_replies_not_read @ 2002-11-12 22:03 UTC (permalink / raw)


Victor Porton:

>Use "use X" directive for a package X only if the package meets the
>following criteria:
[...]

Changing the meaning of "use X" would be a bit stupid IMHO (discussed)
but why not adding a "use limited X" ?
- "limited" is already an Ada keyword
- it is what you are looking for :-)
____________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/index.htm#Ada

NB: For a direct answer, address on the Web site!

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Safe "use" directive
  2002-11-12 22:03 Safe "use" directive Gautier direct_replies_not_read
@ 2002-11-18  1:57 ` Richard Riehle
  0 siblings, 0 replies; 6+ messages in thread
From: Richard Riehle @ 2002-11-18  1:57 UTC (permalink / raw)


Gautier direct_replies_not_read wrote:

> Changing the meaning of "use X" would be a bit stupid IMHO (discussed)
> but why not adding a "use limited X" ?
> - "limited" is already an Ada keyword

I wonder if extending the semantics of the word "limited" might
not add to the confusion.   At present, limited has very strict
meaning and any new use of it ought to correspond closely
(in fact,  exactly) to the current semantics.

Richard Riehle




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2002-11-18  1:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-11-12 22:03 Safe "use" directive Gautier direct_replies_not_read
2002-11-18  1:57 ` Richard Riehle
  -- strict thread matches above, loose matches on Subject: below --
2002-11-08 11:53 Victor Porton
2002-11-08 17:18 ` Peter Richtmyer
2002-11-09 10:36 ` Gautier
2002-11-11 14:44 ` Ted Dennison

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox