comp.lang.ada
 help / color / mirror / Atom feed
From: Ray Blaak <blaak@infomatch.com>
Subject: Re: Ada95 Strengths/Weaknesses.
Date: 1999/09/28
Date: 1999-09-28T00:00:00+00:00	[thread overview]
Message-ID: <m3puz21g7n.fsf@ns24.infomatch.bc.ca> (raw)
In-Reply-To: 7sr7ot$nq9$1@nnrp1.deja.com

In article <7spd4c$9ic2@news.cis.okstate.edu>, David Starner wrote:
> This has nothing to do with what I was talking about. In C++, I can write
> class BigInt, assign integers to it and pass it to templates expecting
> numbers. In fact, I can sed s/int/BigInt/g and add include "bigint.h" to the
> top of all the files, and the programs will run the same (provided, of
> course, that BigInt follows the same semantics as int.) In Ada, I can't write
> a template that expects a integer type and pass a BigInt to it. I can't
> assign to it from universal integer. In Ada, BigInt can't masquarade as a
> number.

You might prefer C++'s ability for classes to work directly with integer
literals, but Ada's "inability" to do this is not by accident, I believe, but
rather result of a philosphical position.

In C++, one can implicitly construct objects from any other object for which
there is a constructor with the appropriate type as a parameter, e.g.,

 BigInt I = 2;

In Ada you cannot. The reason for this is "no implicit conversions". The reason
for *that* is "less bugs". Everything you do to change something's type must be
explicitly done. This makes all such changes visible in the source code, making
what is actually happening easier to understand. It also prevents "accidental"
conversions, which can happen quite a bit in C++ if one is not careful.

I, in fact, generally prefer to see:

  BigInt I := CreateBigInt(2);

and so usually prefer Ada's restriction.

On the other hand, I have been in situations where we did want this implicit
conversion, and justified it due to the cost of migrating an object to a new
class type. We didn't want to break the mountains of old code, so with the
appropriate constructor, a previously exposed raw information string was now
implicitly converted into an appropriately encapsulated object. After a
suitable migration period, we can remove the constructor, after which compiler
errors will quickly point out the (hopefully) few remaining migrations needed.

One of the great things about C++ is that you can control this. Don't supply
the constructors, and the implicit conversions won't happen. In general, C++
done right can be just as correct as Ada. It is just that it is so easy to be
lazy.

If one does want to have Ada source looking closer to implicit conversions of
literals, supply an appropriate definition of the unary "+" (as suggested
elsewhere by Robert Dewar):

 function "+" (i : Integer) return BigInt;

 BigInt I := +2;

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
blaak@infomatch.com                            The Rhythm has my soul.




  reply	other threads:[~1999-09-28  0:00 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-27  0:00 Ada95 Strengths/Weaknesses the middleman
1999-09-27  0:00 ` Marin David Condic
1999-09-27  0:00   ` Hyman Rosen
1999-09-28  0:00     ` Ed Falis
1999-09-28  0:00       ` Hyman Rosen
1999-09-28  0:00         ` Ed Falis
1999-09-28  0:00     ` Robert Dewar
1999-09-28  0:00       ` Preben Randhol
1999-09-28  0:00         ` bill
1999-09-27  0:00           ` Aidan Skinner
1999-09-28  0:00           ` Larry Kilgallen
1999-09-28  0:00           ` Steve Doiel
1999-09-28  0:00           ` Preben Randhol
1999-09-28  0:00   ` Preben Randhol
1999-09-27  0:00 ` David Starner
1999-09-28  0:00   ` the middleman
1999-09-28  0:00   ` Robert Dewar
1999-09-28  0:00     ` Code size of Ada ? was " Alfred Hilscher
1999-09-28  0:00       ` Gautier
1999-09-28  0:00       ` David Botton
1999-09-29  0:00       ` Robert Dewar
1999-09-29  0:00         ` Alfred Hilscher
1999-09-29  0:00           ` Robert Dewar
1999-09-30  0:00             ` Alfred Hilscher
1999-09-30  0:00               ` Robert Dewar
1999-09-30  0:00               ` Gautier
1999-09-29  0:00         ` Larry Kilgallen
1999-09-29  0:00           ` Robert Dewar
1999-09-29  0:00           ` Robert Dewar
1999-09-29  0:00           ` Alfred Hilscher
1999-09-29  0:00             ` Ted Dennison
1999-09-29  0:00             ` Gautier
1999-09-29  0:00               ` Ed Falis
1999-09-29  0:00                 ` tmoran
1999-09-29  0:00                 ` Gautier
1999-09-30  0:00               ` Robert Dewar
1999-09-29  0:00             ` Robert Dewar
1999-09-30  0:00               ` Alfred Hilscher
1999-09-30  0:00                 ` Gautier
1999-09-30  0:00                   ` Robert Dewar
1999-09-30  0:00                   ` Robert Dewar
1999-09-30  0:00                   ` Robert Dewar
1999-09-30  0:00                 ` Robert Dewar
1999-09-30  0:00                   ` tmoran
1999-09-30  0:00                   ` Ehud Lamm
1999-09-30  0:00                     ` Robert Dewar
     [not found]                       ` <7t2e1l$lqt2@ftp.kvaerner.com>
     [not found]                         ` <37F91D6E.58685CFE@mitre.org>
     [not found]                           ` <7tf7uo$h2b$1@nnrp1.deja.com>
     [not found]                             ` <37FBA978.A86762F1@mitre.org>
1999-10-18  0:00                               ` Robert Dewar
1999-10-19  0:00                                 ` Code size of Ada ? Robert I. Eachus
     [not found]                           ` <7tf7uo <37FBA978.A86762F1@mitre.org>
     [not found]                             ` <5OkO3.2$1e.659@typhoon.nyu.edu>
1999-10-19  0:00                               ` Code size of Ada ? was Re: Ada95 Strengths/Weaknesses Robert I. Eachus
1999-09-28  0:00     ` GNAT listing file default names (was: Ada95 Strengths/Weaknesses) Larry Kilgallen
1999-09-28  0:00       ` Gautier
1999-09-29  0:00         ` Robert Dewar
1999-09-29  0:00       ` Robert Dewar
1999-09-29  0:00         ` Larry Kilgallen
1999-09-29  0:00           ` Robert Dewar
1999-09-29  0:00             ` Larry Kilgallen
1999-09-30  0:00               ` Robert Dewar
1999-09-28  0:00     ` Ada95 Strengths/Weaknesses David Starner
1999-09-28  0:00       ` p.obry
1999-09-28  0:00         ` David Starner
1999-09-28  0:00           ` Richard D Riehle
1999-09-28  0:00       ` Gautier
1999-09-28  0:00         ` Ed Falis
1999-09-28  0:00           ` David Starner
1999-09-29  0:00           ` Robert Dewar
1999-09-28  0:00         ` David Starner
1999-09-29  0:00           ` Robert Dewar
1999-09-28  0:00       ` Ted Dennison
1999-09-28  0:00         ` Simon Wright
1999-09-28  0:00       ` Robert Dewar
1999-09-28  0:00         ` David Starner
1999-09-29  0:00           ` Robert Dewar
1999-09-30  0:00         ` Pragma (was Re: Ada95 Strengths/Weaknesses.) Preben Randhol
1999-09-30  0:00           ` Preben Randhol
1999-09-28  0:00       ` Ada95 Strengths/Weaknesses Robert Dewar
1999-09-28  0:00   ` Robert Dewar
1999-09-28  0:00     ` David Starner
1999-09-28  0:00       ` Robert Dewar
1999-09-28  0:00         ` Ray Blaak [this message]
1999-09-28  0:00     ` David Starner
1999-09-29  0:00       ` Robert A Duff
1999-09-27  0:00 ` J. David Bryan
1999-09-27  0:00 ` Steve Doiel
1999-09-28  0:00 ` Geoff Bull
1999-09-28  0:00 ` Geoff Bull
1999-09-29  0:00   ` the middleman
1999-09-29  0:00     ` Robert A Duff
replies disabled

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