comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com>
Subject: Re: Unchecked_Conversion
Date: Mon, 11 Jun 2001 10:21:30 -0400
Date: 2001-06-11T14:21:32+00:00	[thread overview]
Message-ID: <9g2k5c$nt6$1@nh.pace.co.uk> (raw)
In-Reply-To: 41F37C284A6DE8C0.8A6A99719FF11B52.8149DC60E20677C9@lp.airnews.net

This sounds like someone got sent to an Ada class that talked about the
goodness of data types and then they got all excited and started making
*everything* a type - only to discover that you *can* have too much of a
good thing. Types can be good for constraint validation and avoiding the
mixing of things that shouldn't be mixed. However, if every data item you
have is a distinct type, that is rather implying that you never mix them -
and this starts making life miserable. Meters and Seconds are often combined
to produce Meters/Second. Are you gaining some benefit by forcing each to a
different type? (maybe. maybe not.) (BTW: It would be a mistake to think
that Ada *forces* this on you. Just like in C or other languages, you could
do everything as type Integer or Float. Whether or not you should, is an
open question & dependent on your application.)

IMHO, there isn't anything inherently wrong within an application with
saying "Meters and Seconds will never exceed the type Float_64, so they will
both be stored as such" (or possibly as subtypes of Float_64.) This may be
because in your app, you are frequently measuring both and mixing them
mathematically. Where I think strong types make a lot more sense is when you
have to control representation or enforce constraints or you are creating
operations specific to some class of objects. ("Seconds" would want to be a
separate type if I had various time-related functions taking seconds as
parameters & I never wanted those subprograms to accept Meters.) Just
because I'm reading in two values that represent measurements in two
different units does not in and of itself, in my mind, justify creation of
two different types.

There is a bit of "Art" in the construction of good quality code, so you
can't write absolute rules such as "Everything must have its own type!" and
expect goodness to flow out of it. Perhaps there are some books or research
papers that might lead to some Programming Proverbs in this area?

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/


"Robert B. Love " <rlove@antispam.neosoft.com> wrote in message
news:41F37C284A6DE8C0.8A6A99719FF11B52.8149DC60E20677C9@lp.airnews.net...
> My experience runs counter to this.  My employer has chosen to use
> typing for every conceivable measurement. So we have type Meters,
> Meters_Per_Second, Feet, Feet_Per_Second, Seconds, Watts, Volts, and so
> on.
> The list is endless.
>
> To avoid conversions I would have to have hundreds of overloaded
> operators.
> And to make matters worse, we have generic vectors that can be
> instantiated
> for the basic types above.  I would have to have overloaded operators for
> all the vector combinations.
>
> No, using Ada in my problem domain, you are constantly converting types.
> And it can be a pain.
>






  parent reply	other threads:[~2001-06-11 14:21 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-07  7:46 Unchecked_Conversion Lele
2001-06-07 12:50 ` Why not try Checked_Conversion? Petter Fryklund
2001-06-07 13:01 ` Unchecked_Conversion Marc A. Criley
2001-06-07 13:21 ` Unchecked_Conversion Ted Dennison
2001-06-10 18:20   ` Unchecked_Conversion Robert B. Love 
2001-06-10 19:48     ` Unchecked_Conversion Jeff Creem
2001-06-10 22:10     ` Unchecked_Conversion Keith Thompson
2001-06-11 13:56     ` Unchecked_Conversion Ted Dennison
2001-06-11 14:21     ` Marin David Condic [this message]
2001-06-07 14:01 ` Unchecked_Conversion Jacob Sparre Andersen
2001-06-07 19:44 ` Unchecked_Conversion tmoran
2001-06-09 17:07   ` Unchecked_Conversion Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1992-01-02  6:09 unchecked conversion Robert I. Eachus
1991-12-31 13:53 Jean-Pierre Rosen
1991-12-30 23:25 Greg Lomow
replies disabled

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