From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Sharing generic bodies across instantiations.
Date: Tue, 03 Aug 2010 10:37:24 -0400
Date: 2010-08-03T10:37:24-04:00 [thread overview]
Message-ID: <wcciq3ru5i3.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: i380sm$790$1@munin.nbi.dk
"Randy Brukardt" <randy@rrsoftware.com> writes:
> You need to read about the Ada contract model for generics. (Off-hand, I
> can't think of a good reference, however.)
The AARM talks about it. Not exactly an "easy read". ;-)
I think maybe the Ada 83 Rationale talks about it.
There were some holes in the contract model in Ada 83,
which were patched in Ada 95.
>... Part of the Ada contract model is
> that there cannot be an error caused by the actual parameters of an instance
> in an instance body. Tucker Taft liked to describe the model as
> "assume-the-best" in the specification and "assume-the-worst" in the generic
> body. Thus there are a lot of things that are illegal in a generic body in
> Ada simply because they *could* be illegal in some instance of that generic.
> C++ has no such counterpart (indeed, I recall reading that Stoustrup [sp]
> explicitly eliminated it from C++ templates because it was too complex).
>
> In addition, binding of names in the generic body always takes place at the
> point of the compilation of that body. That means that most operations at
> determined at that point, facilitating sharing. (This also causes the
> sometimes bug of "reemergence" in generics, where a hidden predefined
> operator is used instead of the user-defined one for the actual type.) C++
> uses a more macro approach to template expansion.
It makes C++ templates more powerful than Ada generics. The downside is
that if you're writing a reusable and widely-reused library, it's
difficult to know (in C++) whether some change might break clients.
The other downside is that error messages are typically
incomprehensible; in Ada you don't get normally get errors in instance
bodies, so they can't be incomprehensible. ;-)
- Bob
next prev parent reply other threads:[~2010-08-03 14:37 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-27 0:51 Sharing generic bodies across instantiations Peter C. Chapin
2010-07-27 3:01 ` Gene
2010-07-27 6:55 ` AdaMagica
2010-07-27 11:29 ` Ludovic Brenta
2010-07-27 14:10 ` Tero Koskinen
2010-07-27 10:51 ` Martin
2010-07-27 20:06 ` anon
2010-07-27 22:23 ` Peter C. Chapin
2010-07-28 7:59 ` Maciej Sobczak
2010-07-28 9:28 ` Dmitry A. Kazakov
2010-07-28 12:55 ` Maciej Sobczak
2010-07-28 13:16 ` Dmitry A. Kazakov
2010-07-28 19:48 ` Maciej Sobczak
2010-07-29 8:03 ` Dmitry A. Kazakov
2010-07-29 14:02 ` Maciej Sobczak
2010-07-29 14:40 ` Dmitry A. Kazakov
2010-07-29 20:27 ` Maciej Sobczak
2010-07-30 9:09 ` Dmitry A. Kazakov
2010-07-30 12:31 ` Maciej Sobczak
2010-07-30 14:59 ` Dmitry A. Kazakov
2010-08-03 3:02 ` Randy Brukardt
2010-08-03 14:37 ` Robert A Duff [this message]
2010-08-03 2:47 ` Randy Brukardt
2010-07-28 20:01 ` Keith Thompson
2010-07-29 7:46 ` Dmitry A. Kazakov
2010-07-28 11:27 ` Peter C. Chapin
2010-07-28 13:10 ` Maciej Sobczak
2010-07-28 16:32 ` Peter C. Chapin
2010-07-28 19:30 ` Robert A Duff
2010-07-28 20:03 ` Maciej Sobczak
2010-07-28 11:47 ` anon
2010-08-03 2:38 ` Randy Brukardt
2010-08-03 14:31 ` Robert A Duff
2010-07-28 0:55 ` Keith Thompson
2010-07-28 8:42 ` Markus Schoepflin
2010-07-28 11:16 ` anon
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox