comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Untyped Ada?
Date: Sat, 5 Apr 2008 10:44:00 +0200
Date: 2008-04-05T10:44:00+02:00	[thread overview]
Message-ID: <136osxt9jv5ho.xvy2zm6b5kkp.dlg@40tude.net> (raw)
In-Reply-To: 28302e25-844c-41e1-87f1-b4a86146f330@s19g2000prg.googlegroups.com

On Fri, 4 Apr 2008 12:14:38 -0700 (PDT), Graham wrote:

> On Apr 4, 6:38 pm, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> 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 circumstances.
>>> 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.

Yes they do, because it is not hundreds in Ada. It has inheritance and
generics in order to support reuse.

>> 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.

...and the programs usually work, you mean. Granted. Now let us return to
your argument about maintaining hundreds of functions. Considering that
"usual" means 99% of cases, that gives us 1% x 100 = 100% fault rate. Thus
it does *not* work "usually". Further when it does not, how would you find
and fix the problem?

The idea of Ada is that catching inconsistencies earlier is less expensive,
though admittedly more uncomfortable for programmers) than sending bags to
Milan later.

>>> 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.

Thank you for making my argument! The above immediately indicates a
problem. Granted, I am not a financial expert, but I guess it is
semantically wrong. What do you multiply first:

1. (tax_rate * price) * quantity

2. tax_rate * (price * quantity)

I bet only second is correct. So I would insist to define:

function "*" (Left : Money; Right : Natural) return Money;
function "*" (Left : Natural; Right : Money) return Money;
function "*" (Left : Tax_Rate; Right : Money) return Money;
function "*" (Left : Money; Right : Tax_Rate) return Money;

(I wished some syntax to instruct the compiler to derive commutative
operations and complements, as it does for "/=". But this is another story)

>>> 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.

Yet I use exclusively fixed length strings! The trick is that you never
need truly varying strings. If you feel you need it, then try to reconsider
the design, because in most cases varying strings is a wrong design. The
reason is that a string is either the user/GUI/protocol input, which
determines its length, or, when you compose strings, then that is either
primitive catenation or else filling a buffer of a fixed length. 

If you need UTF-8 string handling in Ada, you might have a look at my take
of how it should be:

http://www.dmitry-kazakov.de/ada/strings_edit.htm

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  parent reply	other threads:[~2008-04-05  8:44 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-31 22:44 Untyped Ada? Phaedrus
2008-04-01  0:16 ` Randy Brukardt
2008-04-01  7:19 ` tmoran
2008-04-01  7:44 ` Dmitry A. Kazakov
2008-04-01  8:28 ` Jean-Pierre Rosen
2008-04-01 21:44   ` Phaedrus
2008-04-01 21:51     ` Ludovic Brenta
2008-04-01 17:09 ` Pascal Obry
2008-04-01 22:00   ` Phaedrus
2008-04-02  7:31     ` Dmitry A. Kazakov
2008-04-04 15:16     ` Graham
2008-04-04 16:10       ` Pascal Obry
2008-04-04 21:09         ` Ada.Bounded_Strings Adam Beneschan
2008-04-04 21:15           ` Ada.Strings.Bounded Adam Beneschan
2008-04-05  4:39             ` Ada.Strings.Bounded Gautier
2008-04-05  9:43               ` Ada.Strings.Bounded Pascal Obry
2008-04-05 10:10                 ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-05 11:36                 ` Ada.Strings.Bounded Gautier
2008-04-05 12:14                   ` Ada.Strings.Bounded Pascal Obry
2008-04-06  0:31                     ` Ada.Strings.Bounded Randy Brukardt
2008-04-07 14:57                       ` Ada.Strings.Bounded Adam Beneschan
2008-04-07 15:23                         ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-07 16:34                         ` Ada.Strings.Bounded stefan-lucks
2008-04-07 17:34                           ` Ada.Strings.Bounded (see below)
2008-04-12 18:50                 ` Ada.Strings.Bounded Eric Hughes
2008-04-12 19:46                   ` Ada.Strings.Bounded Georg Bauhaus
2008-04-13 16:53                     ` Ada.Strings.Bounded Eric Hughes
2008-04-13 20:10                       ` Ada.Strings.Bounded Robert A Duff
2008-04-13 23:52                         ` Ada.Strings.Bounded Eric Hughes
2008-04-14  8:00                           ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-14 15:25                             ` Ada.Strings.Bounded Eric Hughes
2008-04-14 18:36                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-15  1:39                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-12 21:09                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-13 16:31                     ` Ada.Strings.Bounded Eric Hughes
2008-04-13 20:02                       ` Ada.Strings.Bounded Robert A Duff
2008-04-13 23:20                         ` Ada.Strings.Bounded Eric Hughes
2008-04-14  9:07                           ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-14 15:50                             ` Ada.Strings.Bounded Eric Hughes
2008-04-14 18:52                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-15  2:07                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-15  8:02                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-15 14:20                                     ` Ada.Strings.Bounded Eric Hughes
2008-04-15 15:23                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-16  2:51                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-16  8:00                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
     [not found]                                     ` <bc3a8b4e-63fe-47a6-b10b-7056f6d7d586@w5g2000prd.googlegroups.com>
2008-04-15 14:58                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-16  2:46                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-16  8:16                                           ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-16 14:40                                             ` Ada.Strings.Bounded Eric Hughes
2008-04-16 18:28                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-21  0:44                                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-21 14:08                                                   ` Ada.Strings.Bounded Robert A Duff
2008-04-21 16:35                                                     ` Ada.Strings.Bounded Eric Hughes
2008-04-21 18:04                                                       ` Ada.Strings.Bounded Robert A Duff
2008-04-22  0:19                                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-22  0:49                                                           ` Ada.Strings.Bounded Adam Beneschan
2008-04-22  1:02                                                             ` Ada.Strings.Bounded Adam Beneschan
2008-04-22 15:30                                                               ` Ada.Strings.Bounded Eric Hughes
2008-04-22 16:08                                                                 ` Ada.Strings.Bounded Robert A Duff
2008-04-22 15:25                                                             ` Ada.Strings.Bounded Eric Hughes
2008-04-22 15:54                                                               ` Ada.Strings.Bounded Robert A Duff
2008-04-22 15:41                                                           ` Ada.Strings.Bounded Robert A Duff
2008-04-22 17:49                                                             ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22 18:26                                                               ` Ada.Strings.Bounded Samuel Tardieu
2008-04-22 18:59                                                                 ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22 18:47                                                             ` Ada.Strings.Bounded Eric Hughes
2008-04-22 19:19                                                               ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22 19:41                                                               ` Ada.Strings.Bounded Robert A Duff
2008-04-22 22:55                                                                 ` Ada.Strings.Bounded Eric Hughes
2008-04-23  6:40                                                                   ` Ada.Strings.Bounded christoph.grein
2008-04-23  6:54                                                                     ` Ada.Strings.Bounded christoph.grein
2008-04-23 10:42                                                                 ` Ada.Strings.Bounded Georg Bauhaus
2008-04-23 12:32                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-23 12:52                                                                   ` Ada.Strings.Bounded christoph.grein
2008-04-23 13:34                                                                     ` Ada.Strings.Bounded Georg Bauhaus
2008-04-23 15:12                                                                   ` Ada.Strings.Bounded Adam Beneschan
2008-04-23 15:36                                                                     ` Ada.Strings.Bounded (see below)
2008-04-23 17:09                                                                     ` Ada.Strings.Bounded Ray Blaak
2008-04-24  0:29                                                                   ` Ada.Strings.Bounded Randy Brukardt
2008-04-22 20:15                                                               ` Ada.Strings.Bounded Adam Beneschan
2008-04-23 13:14                                                                 ` Ada.Strings.Bounded Peter Hermann
2008-04-23 14:40                                                                   ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-23 15:03                                                                     ` Ada.Strings.Bounded Adam Beneschan
2008-04-22 19:56                                                             ` Ada.Strings.Bounded Adam Beneschan
2008-04-21 18:50                                                       ` Ada.Strings.Bounded Dmitry A. Kazakov
2008-04-22  0:31                                                         ` Ada.Strings.Bounded Eric Hughes
2008-04-14 15:11                   ` Ada.Strings.Bounded Adam Beneschan
2008-04-14 16:09                     ` Ada.Strings.Bounded Eric Hughes
2008-04-14 18:13                       ` Ada.Strings.Bounded Georg Bauhaus
2008-04-15  1:35                         ` Ada.Strings.Bounded Eric Hughes
2008-04-15 20:33                           ` Ada.Strings.Bounded Georg Bauhaus
2008-04-16  3:11                             ` Ada.Strings.Bounded Eric Hughes
2008-04-04 23:35           ` Ada.Bounded_Strings Robert A Duff
2008-04-05  1:46             ` Ada.Bounded_Strings Adam Beneschan
2008-04-05  4:55               ` Ada.Bounded_Strings Randy Brukardt
2008-04-05  7:30                 ` Ada.Bounded_Strings Dmitry A. Kazakov
2008-04-06  0:44                   ` Ada.Bounded_Strings Randy Brukardt
2008-04-04 16:18       ` Untyped Ada? Adam Beneschan
2008-04-04 16:32       ` DScott
2008-04-04 17:38       ` Dmitry A. Kazakov
2008-04-04 18:52         ` Georg Bauhaus
2008-04-05  8:07           ` Dmitry A. Kazakov
2008-04-04 19:14         ` Graham
2008-04-04 21:06           ` tmoran
2008-04-05  8:44           ` Dmitry A. Kazakov [this message]
2008-04-12 16:50       ` Eric Hughes
2008-04-04 18:02     ` adaworks
replies disabled

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