comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <bauhaus@futureapps.invalid>
Subject: Re: Functions vs constants
Date: Thu, 24 Jul 2014 10:27:10 +0200
Date: 2014-07-24T10:27:10+02:00	[thread overview]
Message-ID: <lqqg0v$8t6$1@dont-email.me> (raw)
In-Reply-To: <lqpc07$d05$1@loke.gir.dk>

On 24/07/14 00:12, Randy Brukardt wrote:
> "G.B." <bauhaus@futureapps.invalid> wrote in message
> news:lqoab0$bnm$1@dont-email.me...
>> On 23.07.14 00:07, Randy Brukardt wrote:
>>>      with P, Q; use P, Q;
>>>      procedure R is
>>>      begin
>>>          if Error then -- (1)
>>>             raise Error; -- (2)
>>>         end if;
>>>      end R;
>>>
>>> both (1) and (2) are illegal today. But there's no good reason for that;
>>> the
>>> profiles (imagining an extended idea of profile to include objects and
>>> exceptions) are different and there can be no more confusion between them
>>> than between overloaded enumeration literals.
>>
>> Well, this text gives the reader a lucid hint at what the homonyms
>> might mean! Sounds like more context dependency as we have some
>> already, don't we. Good grief.
>
> I think you miss the point. This isn't something that one intentionally
> writes (and "Error" is a terrible name just used for an example). But if one
> intends to reuse code, the client has no control over the naming of the
> entities in the reused code. Moreover (and more important), the client
> shouldn't break due to unrelated maintenance on some third-party code.

I disagree, because the client should perhaps be diagnosed broken, for
reasons of maintainability of references. The latter word is meant
in the generals sense: if it takes a name resolution program to know
the named objects (again in the general sense of the word), then the
program's project management could be steering in a direction of more
helpful naming rather than in that of more complex compiler technology.

That is, if it's broken, fix it. If it needs overloading, take care.
Do not rely on ever more capable, ever more sophisticated overload
resolution technology in this case. IOW, find it suspicious if your
compiler vendor praises a somewhat complicated techno feature that
makes your bundle of homonyms still work!  ;-) ;-) ;-)


> Especially if that third-party code decides to add something with the same
> name as something that you are already using. How could they know to avoid
> it?

Neither can I. (Example below.)

> One could imagine a rule "no use clauses of any kind, anywhere", but that's
> not really practical (especially as it means no infix operator usage). In
> the absence of that, you're going to be at risk for problems. Moreover, even
> if "prefixes are good", they also make code unreadable (particularly if you
> have lots of child packages).

I agree that some kind of abbreviation mechanism is necessary. But not
through overloading, if possible. I'd rather have more errors appearing
(sic), since they can be fixed, rather than having them swept under the
rug, which is what extensive overloading will do. (Hence the example of
Javascript obfuscation; while technically correct, the result is
not maintainable.) That's on the premiss, of course, that a reader of
an ideal Ada program will know the object that some given name denotes
without doing too much resolution himself.

> Ada has many rules that are intended to prevent Beaujolais and Ripple
> effects.

Yes, and I'd like to adduce the rules that make an inner P
hide an outer P, with no "use" in sight. The client might have
to manipulate visibility of names in this case, too.

package P is
    Q : array (Natural range 8 .. 15) of Boolean;
end P;

with P;  -- added, "incompetent programmer" wonders about effect
procedure Client
is
    package P is  --  suppose "competent reviewer" had skipped
                  --  this nested inner P on first reading ...
       function Q (N : Natural) return Boolean;
    end P;

    package body P is separate;

begin
    if P.Q (12) then   --  ... and now both assume things.
       null;
    end if;
end Client;

Writing "with P;" on top of Client doesn't change this program
a bit, provided that P's elaboration has no effects. But it does
change all sorts of assumptions.  Adding more overloading could
not possibly remove the effects of more assumptions?

The same argument applies to with-ing packages from two or more
different libraries, I think. While it might seem tempting to have
a "smart" compiler resolve all naming issues through some kind
of "smart" overloading, I'm reluctant to call that a solution.

It might help getting a particular job done, but since I'm constantly
in a position of having to deal with the results in the long run,
I cannot like it that much.

> To avoid overloading ("homonyms"),
> then you have to avoid "+" and Put and Read and Image and lots of other
> things.

I think that homonyms like "+" and "Put" could be put on the "overriding"
side of "overriding vs overloading", couldn't they? (If we are allowed
to think in terms of a suitably changed language, one that reinterprets
Ada text without changing the effect of code generated for a + b.)

>> This over-overloading, rightfully frowned upon by SPARK ...
>
> SPARK avoids overloading because the original authors of the tools didn't
> have enough knowledge of how to implement it. (...)

[I have turned this political argument---about what is not---around, in the
paragraph about compiler writers who like to sell more overloading. 8-) ]



  parent reply	other threads:[~2014-07-24  8:27 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-21 21:18 Functions vs constants Victor Porton
2014-07-21 21:28 ` Victor Porton
2014-07-21 21:49   ` Shark8
2014-07-21 21:52     ` Victor Porton
2014-07-21 21:59       ` Adam Beneschan
2014-07-21 21:35 ` Niklas Holsti
2014-07-21 21:41   ` Victor Porton
2014-07-21 23:23   ` Randy Brukardt
2014-07-22  7:42     ` Dmitry A. Kazakov
2014-07-22 22:07       ` Randy Brukardt
2014-07-23  7:55         ` Dmitry A. Kazakov
2014-07-23 21:44           ` Randy Brukardt
2014-07-23 12:37         ` G.B.
2014-07-23 22:12           ` Randy Brukardt
2014-07-24  7:20             ` Stefan.Lucks
2014-07-25  4:43               ` Randy Brukardt
2014-07-26  2:36                 ` Shark8
2014-07-24  8:27             ` Georg Bauhaus [this message]
2014-07-24 10:11               ` Dmitry A. Kazakov
2014-07-24 10:49                 ` G.B.
2014-07-24 12:50                   ` Dmitry A. Kazakov
2014-07-25  4:56               ` Randy Brukardt
2014-07-25  6:45                 ` Georg Bauhaus
2014-07-25 10:46                   ` G.B.
2014-07-25 19:31                   ` Randy Brukardt
2014-07-25 20:02                     ` Dmitry A. Kazakov
2014-07-26  2:45                       ` Shark8
2014-07-26  8:02                         ` Dmitry A. Kazakov
2014-07-26 14:03                           ` Shark8
2014-07-26 14:18                             ` Dmitry A. Kazakov
2014-07-21 21:55 ` Victor Porton
2014-07-22  7:06 ` Maciej Sobczak
2014-07-22  7:50   ` Dmitry A. Kazakov
2014-07-22 22:14     ` Randy Brukardt
2014-07-23 13:21       ` Stephen Leake
2014-07-23 13:27         ` Victor Porton
2014-07-23 15:10         ` Adam Beneschan
2014-07-23 21:57 ` Robert A Duff
2014-07-24 12:25   ` Victor Porton
2014-07-24 15:53     ` Robert A Duff
2014-07-24 15:57       ` Victor Porton
2014-07-24 16:47   ` Pascal Obry
2014-07-24 12:26 ` anon
2014-07-24 12:52 ` Victor Porton
2014-07-24 16:01   ` Robert A Duff
2014-07-24 16:15     ` Adam Beneschan
2014-07-25  5:05     ` Randy Brukardt
replies disabled

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