On Apr 4, 6:38 pm, "Dmitry A. Kazakov" <mail...@[EMAIL PROTECTED]
>
wrote:
> On Fri, 4 Apr 2008 08:16:04 -0700 (PDT), Graham wrote:
> > I haven't been using Ada for all that long, but I have been thinking
> > that a kinder, gentler version would be nice in some cir***stances.
> > Not necessarily *no* type-checking, but the ability to mix, say,
> > integers, fixed-point types and floats in an equation without
> > cluttering up the code with conversions.
>
> But you can do that. Provided you knew the semantics of Integer + Float
> your hands are free. Define
>
> function "+" (Left : Integer; Right : Float) return Float;
>
> Here you are.
>
The 'Ada way' is to define lots of types, right? So you could end up
having to maintain hundreds of these functions, couldn't you? Do
people do that? Just curious.
> The compiler does not define it for you for just one reason. The
semantics
> of this operation cannot be universally defined. Integers and Floats
have
> contradicting algebraic properties. + is exact for the former and
inexact
> for the latter. Therefore if adding them makes sense, that is specific
for
> the application which gives an interpretation to Integer and Float in
some
> way. In other words it is your business.
>
That's the kind of almost philosophical argument I find baffling.
People write programs every day that mix integers and floats in
calculations, without any special handling, and the results usually
make sense.
> > I dare say that you wouldn't want to program a missile in such a loose
> > way, but for the kinds of things I'm involved in - financial apps and
> > simulations - the level of strictness of Ada would be a turn-off for
> > many developers.
>
> This puzzles me. Do not financial applications have quite strict
> requirements imposed numeric behavior? Or are you writing for Bear
Stearns?
> (:-))
>
Above all, they have requirements for clarity. Suppose I have
something like:
tax : Money; -- some kind of fixed-point or decimal
tax_rate : Rate; -- some kind of float
quantity : Integer; -- or some such
I want to be able to write:
tax = tax_rate * price * quantity;
Because that way everyone can concentrate on the logic of what's going
on, rather the mechanics of it.
If instead I have to write:
tax = Money(tax_rate * Rate( price ) * Rate( quantity ));
then that's much harder to follow.
I'm open to writing functions like the suggested one:
function "*" (X : Feet; Y : Pounds) returns Foot_Pounds;
I like that idea. But I'd want persuading that it's a practical idea
for a moderately large project.
> > Sorting out string handling out would be nice, too.
>
> What do you mean? In fact Ada's fixed strings handling is the best I
know.
> You should never need Unbounded_String except for rare cases, when you
> wanted to return two strings out of one function.
>
I don't understand that at all. For any web based application (at
least) you need unicode and you can't rely on strings being any
particular length.
Graham


|