comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Hiding the value of Constants
Date: Wed, 8 Jul 2009 14:20:50 +0200
Date: 2009-07-08T14:20:50+02:00	[thread overview]
Message-ID: <12tz12zpoputh.mr1k98qm2wtp.dlg@40tude.net> (raw)
In-Reply-To: 4a547413$0$31878$9b4e6d93@newsspool3.arcor-online.net

On Wed, 08 Jul 2009 12:25:23 +0200, Georg Bauhaus wrote:

> Dmitry A. Kazakov schrieb:
>> On Tue, 7 Jul 2009 13:28:01 -0700 (PDT), Adam Beneschan wrote:
>> 
>>> On Jul 7, 12:53 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
>>> wrote:

>> I believe, nobody is satisfied how the rules handle subprograms
>> and primitive operations. It is too easy to design a package specification
>> which would make it unusable because of ambiguities introduced by
>> "use"-ing. Yes prefix notation makes life easier, but it does not
>> exterminate need in "use". Something quite radical has to be done about it
>> anyway. One spends virtually hours trying to find a reason why the compiler
>> rejects an interpretation the programmer sees as "obvious".
> 
> The programmer seeing something as "obvious" is a hint to
> what the problem with overloading actually is, and what the
> (radical) solution looks like.  (Really radical, in a gardening
> sense, sort of. :-)   Here, again, is the Max example:
> 
>    Max : constant Integer := 15;
>    Max : constant Float := 15.0;
> 
> What seems obvious to me is that the programmer intends to
> express the Max of two somethings that share some common
> property: they both have a Max.  But he/she wishes to do so
> *without* explicitly programming the underlying common
> structure!

I don't see how an underlying structure would help. Consider both Integer
and Float descendants of some Numeric type. Does that change anything? (see
also below)

>  Perhaps it seemed obvious when writing the code,
> or being lazy and not explicitly programming the common
> property seemed justifiable at the time of writing.
> IMHO this is an example of the presumption of "being obvious"
> making things unecessarily complicated: the compiler would
> have to resolve the overload that was introduced by the
> programmer who *knew* how to resolve both the commonality
> and the difference. (There are means in Ada to express
> the same algorithm for two data structures, but anyway ...)

I think that the idea is to express a commonality rather than resolve it.
As an example take Integer'Last and Float'Last. Why they are allowed to be
visible in the same context? How (semantically) they differ from Max?

> The radical solution is to finally get rid of overloading!

Yes, it is a very attractive idea. But the problem is, how to live with "+"
defined both on Integer and Float? As I said earlier, the problem is not
with variables. I think the language will continue reducing the number of
declared variables down to virtually none. The problem is thousands of
operations and types. Where would you get different names for all of them?
How are you going to remember that mess? Consider a typical design of a
library based on generics. It forces you to have identical names for
everything declared in a generic package. The difference happens in the
instances of. The names of the instances is a traditional torture to
invent. As a result they are absolutely meaningless and impossible to
remember. The compiler too has no idea how to help you in finding an
instance of "indexing" a "generic map" with the element "T".

> Just use one name for one thing in one region.  See SPARK
> for an example.
> 
> In Ada, not using generics, but using overridden Max,
> 
>    Bounded_Structure: Finite_Order'class := ...;
> begin
>    if Item < Bounded_Structure.Max then
>       ...

You forgot that a polymorphic operation (Max) is a set of overloaded
specific bodies. You have to allow specific bodies being named. In Ada
these names overload. So the only way not to do it, is to go the path of
C++ by providing unique names mangled by the type signatures, e.g.
Max<Integer>. Interestingly, this is how Ada 83 started. It still has
disgusting attributes taking the form Type'Name. I hope you would agree
that this is a road to hell?

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2009-07-08 12:20 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-07  8:48 Hiding the value of Constants Rick
2009-07-07  8:54 ` xavier grave
2009-07-07  8:58   ` AdaMagica
2009-07-07  9:41 ` Georg Bauhaus
2009-07-07 10:41   ` Hibou57 (Yannick Duchêne)
2009-07-07 15:51     ` Adam Beneschan
2009-07-07 16:26       ` Hibou57 (Yannick Duchêne)
2009-07-07 18:48       ` Dmitry A. Kazakov
2009-07-07 19:05         ` Adam Beneschan
2009-07-07 19:53           ` Dmitry A. Kazakov
2009-07-07 20:28             ` Adam Beneschan
2009-07-07 20:57               ` Dmitry A. Kazakov
2009-07-08 10:25                 ` Georg Bauhaus
2009-07-08 12:20                   ` Dmitry A. Kazakov [this message]
2009-07-09 23:04 ` anon
2009-07-10  6:37   ` AdaMagica
2009-07-11 19:06     ` anon
2009-07-11 19:26       ` Georg Bauhaus
2009-07-11 21:53         ` anon
2009-07-11 22:03           ` Albrecht Käfer
2009-07-11 22:15           ` Ed Falis
2009-07-15  9:30             ` anon
2009-07-11 23:31           ` Egil
replies disabled

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