From: Stephen Leake on
Anonymous Coward <spam(a)spam.com> writes:

> In article <ulkzmsw5v.fsf(a)acm.org>, Stephen Leake wrote:
>>
>> You introduced a name collision by the 'use' clause; that can always
>> cause name collisions. The proper solution in that case is to use
>> the qualified name.
>
> I agree. I personally take it an extreme step further, and never use
> use clauses anywhere. They shouldn't even be in the language. Every
> Ada project I've worked on that had a coding standard banned the use
> clause, and rightly so.

Hmm. Even for operators?

A := B + C;

should work when A, B, C are Cartesian Vectors, not just scalars.

And a use clause in a small function can easily improve readability.

> I don't only oppose it because of the ambiguity, but even when there
> is no ambiguity, it's a severe inconvenience to have to grep a large
> tree to hunt down a declaration.

As others have said, get a real editor.

> Clearly the typing time saved by the use clause cannot possibly offset
> the time lost on all the resulting code searches.

It's not the time typing I'm worried about, it's the time reading and
understanding.

--
-- Stephe
From: Anonymous Coward on
In article <uwtj4xc6j.fsf(a)acm.org>, Stephen Leake wrote:
>
> Hmm. Even for operators?
>
> A := B + C;
>
> should work when A, B, C are Cartesian Vectors, not just scalars.
>
> And a use clause in a small function can easily improve readability.

That's what the "use type" clause is for. I have no objection to the
use type clauses. I use them myself, and coding standards always
accommodate them.

>> I don't only oppose it because of the ambiguity, but even when there
>> is no ambiguity, it's a severe inconvenience to have to grep a large
>> tree to hunt down a declaration.
>
> As others have said, get a real editor.

The version of emacs they've installed at work does not have this
capability, and I'm stuck with what they provide; but it wouldn't
matter anyway. Even with that feature (which I've had on previous
projects), it wouldn't be worth it to constantly search like that,
when disciplined Ada programmers can simply follow the coding standard
and fully qualify external identifiers.

As a beginner I was tempted to use the use, but after I was forced to
fully qualify, I've discovered that it's much easier to read code from
others as well as old code of my own. I would never go back, even if
Emacs had a mouseover cross reference.

>> Clearly the typing time saved by the use clause cannot possibly
>> offset the time lost on all the resulting code searches.
>
> It's not the time typing I'm worried about, it's the time reading
> and understanding.

In that case the time you're worried about is what's reduced by fully
qualifying your names. If you get the information as fast as you can
read it, you know what's going on faster than you can even reach for
your mouse. You just cannot beat instantaneously knowing which names
are internal and which are not, and where they come from.

There is one case where I might be willing to tolerate the use clause
on a project. If an editor existed that would fully qualify the names
(inline) as it loads the buffer so I wouldn't even need to hover over
them with a mouse, and the project supported such a tool, then it
wouldn't matter to me either way whether I had to read code that used
use clauses. AFAIK, no such tool exists, or at least it's certainly
not mainstream.

A better approach would be to have the controlled code checked in
without use clauses, and if some hacker wants the package names
hidden, or other hidden information for that matter, then it would be
easier to make that a check out for browse option.

At one point I worked on a project that did not enforce their
prohibition on the use clause. They simultaneously mandated a lousy
Windows-based tool set, which did not have cross referencing, and to
worsen things, grep was not provided either. So we had to search
using the crappy native Microsoft search tool, which does not support
regular expressions. The folks on that project who used use clauses
needlessly robbed me of copious manhours.
From: Pascal Obry on
Anonymous Coward a ?crit :
> I don't only oppose it because of the ambiguity, but even when there
> is no ambiguity, it's a severe inconvenience to have to grep a large
> tree to hunt down a declaration. Then to possibly get multiple hits
> and have to compare two lists of packages to discover which hit is the
> correct one. By the time you make it to the declaration you're
> looking for, you've forgotten why you need to look at it :)

Or you use GPS :) Or any decent IDE that can jump to the rigth place for
you !

Pascal.

--

--|------------------------------------------------------
--| Pascal Obry Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--| http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595
From: Dmitry A. Kazakov on
On Sat, 19 Nov 2005 23:40:46 GMT, Anonymous Coward wrote:

> In article <1ef4kvy6kdkwz.oqmb8acj5joo.dlg(a)40tude.net>,
> Dmitry A. Kazakov wrote:
>>
>> No, name collisions better be prevented by making "use" illegal when
>> it hides anything.
>
> The use clause is barred by coding standards for a good reason, and I
> don't think it's necessarily name collisions that drive this rule.

What else then?

> Programmers are forced to resolve name collisions, with or without the
> USE clause.

No. Don't refer to conflicting names and the compiler won't object. This is
IMO bad.

> The use clause is banned because it makes code unreadable
> and difficult to use. As Joel Spolsky said, travel should be minimal
> when interpretting a line of code. Fully qualified naming is a better
> style because you know immediately, from the code itself, where the
> identifier lives. And if you need to see the declaration, you know
> immediately where to go.

How so? Why should I care about the declaration/definition places? What
should be a fully qualified name of a dispatching call to a 10-times
overridden primitive operation, provided that 5 of them were private? The
first, the last, one in the middle?

>> BTW, what about banning implicit "use" of "Standard"? Care to write
>> an AI to make Integer, "+", "-" etc invisible? (:-))
>
> The "use type" clause is a different beast, and I do not object to its
> use; nor is it banned in any coding standard I've read.

What is the difference between "+" and "Add"?

>>> Then to possibly get multiple hits and have to compare two lists of
>>> packages to discover which hit is the correct one. By the time you
>>> make it to the declaration you're looking for, you've forgotten why
>>> you need to look at it :)
>>
>> It is no matter "where", "what" does matter. If you need to
>> frequently browse sources to determine "what", then the program is
>> poorly designed.
>
> Certainly not. I would say just the opposit. If you're repeating
> information from your declaration in your identifiers, then you've
> created a maintenance problem by introducing too much noise, also
> forcing identifiers to change whenever the declaration changes. A
> good design doesn't repeat this information.

It seems that you are arguing my point. Name prefix is that noise you are
talking about.

>>> Clearly the typing time saved by the use clause cannot possibly offset
>>> the time lost on all the resulting code searches.
>>
>> What about the time spent on reading something like A.B.C.D.E.F.G.H?
>
> If you have something like that, then there's something wrong with the
> architecture of your project. A user should not need visibility into
> such a deep level within an external component.

That might be true, but irrelevant because the implementation of H should
know A and A.B and A.B.C etc. According to your theory within H anything
from G must be referred as A.B.C.D.E.F.G.X!

Now if you aren't going to argue against child packages, consider "use A"
as an ad-hoc parent specification.

BTW, one probably could even remove "use" from the language allowing
multiple parents instead.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
From: David Emery on
I've been in the middle of several debates on this. My personal strong belief and experience has been that qualified names are very useful in comprehension, particularly trying to grasp the 'big picture' of software structure.

So in one previous life, when handed a package that did not have qualified names in it, the first thing I'd do is add the qualified names.

it's possible to construct programming environments that can show you the unambiguous source for each name/operator. But such information is transient, it only lasts for as long as you have the mouse/etc there. Often I'm sufficiently "Luddite" that I print out and scribble over hardcopies of programs.

dave

Ed Falis wrote:
> On Sat, 19 Nov 2005 15:28:25 -0500, Anonymous Coward <spam(a)spam.com> wrote:
>
>> I don't only oppose it because of the ambiguity, but even when there
>> is no ambiguity, it's a severe inconvenience to have to grep a large
>> tree to hunt down a declaration. Then to possibly get multiple hits
>> and have to compare two lists of packages to discover which hit is the
>> correct one. By the time you make it to the declaration you're
>> looking for, you've forgotten why you need to look at it
>
>
> If you were using a modern editor, with Ada cross-referencing, you
> wouldn't have this problem. GPS, emacs Ada mode, ObjectAda and quite a
> few others provide this.
>
> - Ed
First  |  Prev  |  Next  |  Last
Pages: 1 2 3 4
Prev: Debugger for GNAT
Next: Help installing GCC/GNAT 4.0.2