comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: XML DOM Binding for Ada 95 - matter of style
Date: Thu, 07 Aug 2003 17:03:18 +0200
Date: 2003-08-07T17:03:18+02:00	[thread overview]
Message-ID: <0qm4jvgtbf3jibvf9vkdv9i4fvjrgn3soc@4ax.com> (raw)
In-Reply-To: wYrYa.424$Nf3.323@newsread4.news.pas.earthlink.net

On Thu, 07 Aug 2003 12:52:44 GMT, "Matthew Heaney"
<matthewjheaney@earthlink.net> wrote:

>"Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> wrote in message
>news:egd1jvc6pe888e4ug683tis6a5q5ua12ml@4ax.com...
>> On Tue, 5 Aug 2003 13:34:09 +0000 (UTC), Georg Bauhaus
>> <sb463ba@d2-hrz.uni-duisburg.de> wrote:
>>
>> >Actually, you can pass operations of a tagged type as actuals.
>>
>> Yes, this is a great disadvantage of generics. You have to explicitly
>> specify everything you need.
>
>This is a feature, not a flaw.  The Ada generics were deliberately designed
>this way, because you get better error checking.

Yes. Better error checking is because of a better contract
specification. Flaw is that with generics one cannot inherit the
contract and extend/modify it. There are actually two ways to make
something close to that:

1. To define a generic package with "interface" functions and pass its
instance as formal parameter to another generic package.

2. To use child generic packages.

Both are far not so flexible and easy to use as classical interface
inheritance.

>> Compare it with inheritance, you just
>> specify a base type.  This is because Ada's generics try to pretend to
>> have some contract.
>
>I don't know what you mean by "pretend" to have a contract: Ada generics do
>have a contract.  In fact it's called the "generic contract model."

A very limited one. There are many things, which cannot be [precisely]
specified in the contract. For example, you cannot have user-defined
type classes, you have to stick to the predefined ones, like "(<>)",
"range <>", "mod <>", "private". There are problems with information
hiding when generics are used. etc

Anyway, if one wish to argue for generics against tagged types, one
should rather consider C++ templates. All (mosty mythical) advantages
over tagged types appear when one departs from the contract model.
Stricter we make contracts lesser difference we will notice. As a
prophecy, in the end, tagged types will completely supersede generics.

>> C++ does not, it openly says that what you become
>> is your own business.
>
>Well, yes and no.  You don't just design ex nihilo, but with the expection
>that the generic actual type will have a specific set of operations, even if
>those operations are only loosely specified.
>
>> template <class Element>void Sort ...;
>>    // Guess, what I have used here this week, "<=" or ">="?
>
>No.  Sort will only use operator<.  It will never use operator<= or
>operator>=, because those can be derived from the canonical operator<.

The contract states neither this nor otherwise. It is a clear flaw.
One could argue that it is an advantage, because "every reasonable
programmer would make so", but then I would argue that one need no
type system at all, because "every reasonable programmer will never
mix incompatible types".

>You should always define relational operators in terms of the less-than
>operatior:
>
>function "<" (L, R : T) return Boolean is ...;
>
>function ">" (L, R : T) return Boolean is
>begin
>   return R < L;
>end;
>
>function ">=" (L, R : T) return Boolean is
>begin
>   return not (L < R);
>end;
>
>function ">=" (L, R : T) return Boolean is
>begin
>   return R <= L;
>end;
>
>In the STL and in Charles, you even use the less-then operator for computing
>"equivalence" of keys:
>
>function Is_Equivalent (L, R : T) return Boolean is
>begin
>   return not (L < R) and not (R < L);
>end;
>
>The equality operator "=" for elements is only used to compute the value of
>container equality.

How does this support templates?

However this is a point for future Ada revisions. If the compiler
derives "/=" from "=", why doesn't it for "<"? Similar thing is
commutative operations like "+" and "*". One could wish to derive
"+"  (Left : Y; Right : X) from "+"  (Left : X; Right : Y) instead of
a geometric explosion of specifications in case of many types.

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-08-07 15:03 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-30 11:32 XML DOM Binding for Ada 95 - matter of style DENNY VRANDECIC
2003-07-30 12:33 ` Martin Dowie
2003-07-30 15:20   ` Denny Vrandecic
2003-07-30 16:33     ` Stephen Leake
2003-07-31 10:57       ` Marin David Condic
2003-07-31 11:27         ` Preben Randhol
2003-07-31 13:10           ` Matthew Heaney
2003-07-31 19:04             ` Simon Wright
2003-08-02 14:40               ` Matthew Heaney
2003-07-31 20:25             ` Randy Brukardt
2003-08-01 11:46           ` Marin David Condic
2003-08-02  3:40             ` Matthew Heaney
2003-08-02 12:08               ` Marin David Condic
2003-08-02 14:46                 ` Matthew Heaney
2003-08-02 21:25                   ` Ed Falis
2003-08-05 19:59                   ` Marin David Condic
2003-08-03 16:42                 ` Matthew Heaney
2003-08-04  8:04                   ` Dmitry A. Kazakov
2003-08-05  8:00                     ` Georg Bauhaus
2003-08-05 11:46                       ` Dmitry A. Kazakov
2003-08-05 13:34                         ` Georg Bauhaus
2003-08-06  9:03                           ` Dmitry A. Kazakov
2003-08-06 18:15                             ` signature like constructions (was: Re: XML DOM Binding for Ada 95 - matter of style) Georg Bauhaus
2003-08-07 10:12                               ` Dmitry A. Kazakov
2003-08-07 16:22                                 ` signature like constructions Georg Bauhaus
2003-08-08  8:31                                   ` Dmitry A. Kazakov
2003-08-08 10:12                                     ` Robert I. Eachus
2003-08-08 13:29                                       ` Dmitry A. Kazakov
2003-08-08 19:37                                         ` Robert I. Eachus
2003-08-09  0:58                                           ` Alexander Kopilovitch
2003-08-09  7:39                                             ` Robert I. Eachus
2003-08-10  1:30                                               ` Alexander Kopilovitch
2003-08-10  4:11                                                 ` Robert I. Eachus
2003-08-11 10:25                                           ` Dmitry A. Kazakov
2003-08-08 23:44                                         ` Alexander Kopilovitch
2003-08-11  9:54                                           ` Dmitry A. Kazakov
2003-08-11 14:59                                             ` Alexander Kopilovitch
2003-08-12  9:54                                               ` Dmitry A. Kazakov
2003-08-13 22:28                                                 ` Alexander Kopilovitch
2003-08-09  8:32                                       ` Simon Wright
2003-08-09 15:32                                         ` Robert I. Eachus
2003-08-07 12:52                             ` XML DOM Binding for Ada 95 - matter of style Matthew Heaney
2003-08-07 15:03                               ` Dmitry A. Kazakov [this message]
2003-08-07 12:28                           ` Matthew Heaney
2003-08-05 20:05                   ` Marin David Condic
2003-07-30 16:34     ` Martin Dowie
2003-07-30 17:54 ` tmoran
replies disabled

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