comp.lang.ada
 help / color / mirror / Atom feed
From: Ludovic Brenta <ludovic@ludovic-brenta.org>
Subject: Re: Alternatives to C: ObjectPascal, Eiffel, Ada or Modula-3?
Date: Tue, 21 Jul 2009 00:54:29 -0700 (PDT)
Date: 2009-07-21T00:54:29-07:00	[thread overview]
Message-ID: <30db0781-f919-4bab-acc0-b7034526ed83@y19g2000yqy.googlegroups.com> (raw)
In-Reply-To: h435uc$djn$1@aioe.org

On Jul 21, 3:33 am, Cesar Rabak <csra...@yahoo.com.br> wrote:
> Ludovic Brenta escreveu:
>
>
>
> > Cesar Rabak wrote on comp.lang.eiffel, comp.lang.ada:
> >> Nicholas Paul Collin Gloucester escreveu:
> > [...]
> >>> In this case there is a reason for having more types. An angle and a
> >>> length are simply not interchangable, so they should not be
> >>> represented both by Float. The amount of money equal to U.S.$1.00 is
> >>> not equal to the amount of money equal to 1.00 Canadian dollar, but
> >>> they are both written with the number 1.00.
> >> I disagree strongly: an angle in radians is a real number as any other
> >> there is not any intrinsic difference in its *type* on ordinary
> >> Mathematics.  Dimensionally they are 'pure numbers' with no unit
> >> atached, your example on monetary units being fallacious, so non
> >> sequitur.
>
> > Ada is not a language for mathematicians (mathematicians would rather
> > use e.g. Octave), it is a language for engineers.  In engineering,
> > there are very few pure numbers and quite a lot of dimensioned
> > numbers.  As an engineer, I certainly view angles, frequencies and
> > dimensionless constants (e.g. correction factors) as all having
> > different dimensions.
>
> Nice you bring this, Ludovic! However, remember the OP question:
> <quote>
> I'm a CS student and I often need to write number-crunching code dealing
> with combinatorial optimization problems.
> What I do usually is implementing ad-hoc algorithms and testing their
> performance against other previously-known solutions, including general
> solvers.
> </quote>
>
> So your suggestion is to steer from Ada?

No, I would personally use Ada and make the number-crunching code into
generic units.  The user would then provide their application-defined
floating-point type as a generic parameter to instantiate the code.

> > I would have declared the types for angles thus:
> > type Radians is new Float; -- no range restriction
>
> > You focused too much, IMHO, on the range restriction which is not the
> > important part.  The important part is that, in Ada, this declares a
> > new *type* (not a "subtype" or "nickname for Float"), which is
> > *incompatible* with Float or any other type.  
>
> More or less. It has all the operations of the derived type, uses the
> same representation on the machine.  The incompatibility is syntactic no
> in its essence.
>
> For example: which type is the operation X^2 + Y^2, or Magnitude *
> cos(Theta)?

Simple.  In Ada, these expressions are illegal.  The user must
explicitly convert some of the values to a compatible type before
being allowed to mix objects of different types, e.g.

X : Horizontal_Coordinate := ...;
Y : Vertical_Coordinate := ...
R : Magnitude := Magnitude (X)**2 + Magnitude (Y)**2;
X := Horizontal_Coordinate (R) * Magnitude (cos (Theta));

You may say is it not "ergonomic" but, as an engineer, I see this as
"saying what you mean".  The best approach, of course, is to make the
above operations into application-specific operators, e.g.

function Magnitude_Of (X : Horizontal_Coordinate; Y :
Vertical_Coordinate)
  return Magnitude;

> Does the subtyping in Ada complain if one makes an operation on two
> variables of type Length (here defined as 'type Length is new Float;')
> that there is not a compatible Length squared defined?

No, unfortunately.  In Ada, Length squared is a Length.  There are
however libraries like [1] that allow full dimensioned computations.
They use compile-time checks where possible and run-time checks where
necessary.

[1] http://www.dmitry-kazakov.de/ada/units.htm

> > This incompatibility has
> > two benefits: early detection of some errors (except, of course, those
> > involving literals of type universal_real) and documentation, to the
> > human reader, of what objects of the type represent in the real world.
>
> I agree this allows for some error protection, but as I showed already
> this only happens *after* the variable has been initialized with a value
> which for non trivial programs have to come from outside world.

No.  The incompatibility between types is checked at compile time and
does not depend on values.  Indeed, it still works if all types are
declared as "new Float" with no range restriction.

> > [...]
> >>> Nothing is foolproof, but I did prevent some accidents.
> >> Yes, I agree on that and Ada has been a step forward on this direction,
> >> but as has been written elsewhere in this thread, Ada types do not form
> >> a 'type system' so it brings moderate safety against errors.
>
> > In Ada, floating-point literals (which were the crux of your argument)
> > belong to the type universal_real which allows implicit conversion to
> > any floating-point type.  If I understand your argument correctly, you
> > are suggesting that universal_real (and universal_integer) should
> > disappear and that the language should force the programmer to qualify
> > every literal, i.e.:
>
> > X : Radians := Radians'(3.0);
>
> Why? Doesn't it make sense for you?
>
> How would Ada gurus suggest the interfaces for reading data from outside
> the program (GUI, command line parameters, fields in files, etc.) be
> coded (in order to make full use of Ada features)?

The interfaces for reading from the outside already exist and they all
use typed input-output routines which check for range constraints (if
applicable) at run time. This makes is simply impossible to create
untyped values, or values of type universal_real, from outside the
program source. One example with streams:

   type Radians is new Float;
   F : Ada.Streams.Stream_IO.File_Type;
begin
   Ada.Streams.Stream_IO.Open (File => F,
                               Mode => Ada.Streams.Stream_IO.In_File,
                               Name => "foo.dat");
   declare
      S : constant Ada.Streams.Stream_IO.Stream_Access :=
        Ada.Streams.Stream_IO.Stream (F);
      R : Radians;
   begin
      Radians'Read (Stream => S, Item => R);
   end;
end;

(note : I wrote the above in an extra-verbose style to make context
unnecessary).

--
Ludovic Brenta.



  reply	other threads:[~2009-07-21  7:54 UTC|newest]

Thread overview: 285+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-18 14:19 Alternatives to C: ObjectPascal, Eiffel, Ada or Modula-3? Andrea Taverna
2009-07-18 14:42 ` Richard Harter
2009-07-18 14:53 ` Francois PIETTE
2009-07-18 15:23   ` Ludovic Brenta
2009-07-18 18:27     ` Andrea Taverna
2009-07-18 18:46       ` Pascal Obry
2009-08-04 20:09         ` Hendrik Boom
2009-08-04 21:35           ` Jon Harrop
2009-07-18 18:57       ` Andrea Taverna
2009-07-18 15:18 ` Pascal J. Bourguignon
2009-07-19 13:50   ` Andrea Taverna
2009-07-19 14:06     ` Pascal J. Bourguignon
2009-07-20 10:13   ` Nicholas Paul Collin Gloucester
2009-08-04 20:12     ` Hendrik Boom
2009-07-21 12:03   ` Jon Harrop
2009-07-21 13:25     ` Mark T.B. Carroll
2009-07-18 15:50 ` Ludovic Brenta
2009-07-18 16:31   ` Hibou57 (Yannick Duchêne)
2009-07-18 19:48   ` Georg Bauhaus
2009-07-20 10:34   ` Nicholas Paul Collin Gloucester
2009-07-23 22:58   ` A few Ada questions Andrea Taverna
2009-07-24  0:28     ` Ludovic Brenta
2009-07-24  9:07       ` AdaMagica
2009-07-28  9:48         ` Making a nonlimited type controlled by means of a controlled component Ludovic Brenta
2009-08-14 22:21           ` Randy Brukardt
2009-08-14 22:51             ` Adam Beneschan
2009-07-24  7:00     ` A few Ada questions Dmitry A. Kazakov
2009-07-24 15:26       ` Colin Paul Gloster
2009-07-24 15:01         ` Dmitry A. Kazakov
2009-07-18 16:27 ` Alternatives to C: ObjectPascal, Eiffel, Ada or Modula-3? BGB / cr88192
2009-07-18 17:41 ` Ben Bacarisse
2009-07-20 10:39   ` Nicholas Paul Collin Gloucester
2009-07-20 16:17     ` Ben Bacarisse
2009-07-21 12:10     ` Jon Harrop
2009-07-21 14:40       ` Colin Paul Gloster
2009-07-22  0:25         ` Andrew Reilly
2009-07-19  1:04 ` Andrew Reilly
2009-07-19 13:14   ` mockturtle
2009-07-19 13:35   ` Andrea Taverna
2009-07-19 15:28     ` Pascal J. Bourguignon
2009-07-19 17:30       ` Hibou57 (Yannick Duchêne)
2009-07-19 18:02       ` Georg Bauhaus
2009-07-19 19:09         ` Hibou57 (Yannick Duchêne)
2009-07-19 19:14         ` Pascal J. Bourguignon
2009-07-19 19:51           ` Georg Bauhaus
2009-07-19 19:52 ` tm
2009-07-20  9:57 ` Jean-Pierre Rosen
2009-07-20 13:42   ` Hibou57 (Yannick Duchêne)
2009-07-20 14:37   ` tm
2009-07-20 15:14     ` Jean-Pierre Rosen
2009-07-24  7:26       ` tm
2009-07-24  8:10         ` Dmitry A. Kazakov
2009-07-25 17:39           ` Frank J. Lhota
2009-07-25 18:12             ` Dmitry A. Kazakov
2009-07-24 21:15         ` Wolfgang Ehrhardt
2009-07-24 22:29           ` bartc
2009-07-26 10:55             ` tm
2009-07-26 12:14               ` bartc
2009-07-26 13:21                 ` Pascal J. Bourguignon
2009-07-26 15:43                   ` bartc
2009-07-20 15:46     ` Georg Bauhaus
2009-07-20 16:08     ` Ben Bacarisse
2009-07-20 19:48     ` Tetrahedral Quartz
2009-07-26  2:26   ` wwilson
2009-07-20 12:15 ` Nicholas Paul Collin Gloucester
2009-07-20 12:59   ` Mark T.B. Carroll
2009-07-20 13:18     ` Nicholas Paul Collin Gloucester
2009-07-20 13:21       ` Mark T.B. Carroll
2009-07-20 14:49         ` Nicholas Paul Collin Gloucester
2009-07-20 18:33   ` Cesar Rabak
2009-07-20 18:49     ` Hibou57 (Yannick Duchêne)
2009-07-20 19:35       ` Cesar Rabak
2009-07-20 21:54         ` Georg Bauhaus
2009-07-21  7:39         ` Dmitry A. Kazakov
2009-07-21 14:30           ` Cesar Rabak
2009-07-21 15:17             ` Martin
2009-07-20 19:23     ` Georg Bauhaus
2009-07-20 19:55       ` Cesar Rabak
2009-07-21 12:49       ` Colin Paul Gloster
2009-07-20 19:44     ` Nicholas Paul Collin Gloucester
2009-07-20 20:14       ` Cesar Rabak
2009-07-20 22:22         ` Ludovic Brenta
2009-07-21  1:33           ` Cesar Rabak
2009-07-21  7:54             ` Ludovic Brenta [this message]
2009-07-21  7:59             ` Dmitry A. Kazakov
2009-07-21 13:08               ` Colin Paul Gloster
2009-07-21 12:43                 ` Dmitry A. Kazakov
2009-07-21 14:48                 ` Cesar Rabak
2009-07-21 14:45               ` Cesar Rabak
2009-07-21 15:46                 ` Dmitry A. Kazakov
2009-07-21 17:34                   ` Colin Paul Gloster
2009-07-21  8:56             ` Jean-Pierre Rosen
2009-07-21  9:31               ` Georg Bauhaus
2009-07-21 15:02               ` Cesar Rabak
2009-07-21 16:42                 ` Georg Bauhaus
2009-07-21 18:00                   ` Cesar Rabak
2009-07-22 14:10                     ` Colin Paul Gloster
2009-07-22 14:54                       ` Cesar Rabak
2010-03-24  2:46                       ` Robert Love
2010-03-25 15:51                         ` Colin Paul Gloster
2009-07-21 17:37                 ` Colin Paul Gloster
2009-07-21 14:08             ` Hibou57 (Yannick Duchêne)
2009-07-21 13:38         ` Colin Paul Gloster
2009-07-21 15:25           ` Cesar Rabak
2009-07-21 17:48             ` Colin Paul Gloster
2009-07-23 18:47               ` Jon Harrop
2009-07-23 19:20                 ` Colin Paul Gloster
2009-07-23 21:51                   ` Jon Harrop
2009-07-24  1:08                   ` Cesar Rabak
2009-07-24  7:04                     ` Dmitry A. Kazakov
2009-07-22 19:29   ` sjw
2009-07-22 20:05     ` Dmitry A. Kazakov
2009-07-23 12:01     ` Colin Paul Gloster
2009-07-24  1:19       ` Cesar Rabak
2009-07-24  8:50         ` Georg Bauhaus
2009-07-24 15:56           ` Colin Paul Gloster
2009-07-24 16:52         ` Colin Paul Gloster
2009-07-24 18:36           ` Cesar Rabak
2009-07-24 21:46           ` Robert A Duff
2009-07-25 14:32             ` jimmaureenrogers
2009-07-25 17:31             ` Cesar Rabak
2009-07-21 12:25 ` Jon Harrop
2009-07-21 11:41   ` Martin
2009-07-21 14:09     ` Jon Harrop
2009-07-21 13:41       ` Martin
2009-07-21 13:45         ` Martin
2009-07-21 13:58         ` Dmitry A. Kazakov
2009-07-21 16:06         ` Jon Harrop
2009-07-21 15:54           ` Georg Bauhaus
2009-07-22  9:37             ` Jon Harrop
2009-07-22  9:19               ` Georg Bauhaus
2009-07-22  7:53           ` Martin
2009-07-22  9:18             ` Jon Harrop
2009-07-21 23:17         ` Robert A Duff
2009-07-21 14:12   ` Andrea Taverna
2009-07-21 14:14     ` Hibou57 (Yannick Duchêne)
2009-07-21 14:38     ` Hibou57 (Yannick Duchêne)
2009-07-21 15:29       ` Mark T.B. Carroll
2009-07-21 16:10     ` Jon Harrop
2009-07-22  8:16       ` Martin
2009-07-22 18:59         ` Jon Harrop
2009-07-24  8:15     ` tm
2009-07-24  9:31       ` Jon Harrop
2009-07-24  9:42         ` Georg Bauhaus
2009-07-24 13:03           ` Jon Harrop
2009-07-24 10:15         ` tm
2009-07-24 13:11           ` Jon Harrop
2009-07-24 13:01             ` tm
2009-07-24 14:42               ` Jon Harrop
2009-07-25  1:15         ` wwilson
2009-07-25  6:05           ` robertwessel2
2009-07-25  9:24             ` Dmitry A. Kazakov
2009-07-26  2:10             ` wwilson
2009-07-26  3:27               ` Andrew Reilly
2009-07-26 10:08                 ` bartc
2009-07-27 11:28               ` Colin Paul Gloster
2009-07-28  5:01                 ` wwilson
2009-07-28 10:13                   ` Colin Paul Gloster
2009-07-28 12:29                   ` Dave Seaman
2009-07-28 12:42                     ` Peter Hermann
2009-07-28 18:35                     ` wwilson
2009-07-21 13:09 ` parnell
2009-07-28 20:57 ` fft1976
2009-07-28 21:59   ` Georg Bauhaus
2009-07-28 22:01   ` Ludovic Brenta
2009-07-30  3:04     ` fft1976
2009-07-30  6:47       ` Martin
2009-07-28 23:14   ` Jon Harrop
2009-08-01 19:46     ` frankenstein
2009-08-01 21:56       ` Paul Rubin
2009-08-01 23:28         ` Jon Harrop
2009-08-02 10:07         ` frankenstein
2009-08-02 18:55           ` Jon Harrop
2009-08-02  9:48       ` frankenstein
2009-07-29  0:40   ` Oxide Scrubber
2009-07-29  2:52     ` fft1976
2009-07-29  4:46       ` Oxide Scrubber
2009-07-29  7:50   ` Elena
2009-07-29 15:06     ` Andrea Taverna
2009-07-29  8:11   ` Ray Blaak
2009-07-29  9:57     ` learn2code
2009-07-29 11:38       ` Oxide Scrubber
2009-07-29 14:03         ` learn2code
2009-07-29 14:35           ` Pascal J. Bourguignon
2009-07-29 17:02           ` Oxide Scrubber
2009-08-03 11:19             ` oxhiderubber
2009-07-29 21:10           ` Jon Harrop
     [not found]         ` <kctwcdo5pewe.1ut3dcff8axm0$.dlg@40tude.net>
2009-07-29 21:18           ` Jon Harrop
2009-07-29 16:36       ` Colin Paul Gloster
2009-07-29 17:22       ` Ray Blaak
2009-07-29 18:44     ` Martin
2009-07-29 20:58       ` Jon Harrop
2009-07-29 15:19   ` Andrea Taverna
2009-07-29 19:25     ` Jon Harrop
2009-07-30  2:11   ` tmoran
2009-07-30  2:34     ` fft1976
2009-07-30  2:48       ` Paul Rubin
2009-07-30  3:40         ` fft1976
2009-07-30  3:53           ` Paul Rubin
2009-07-30  6:51           ` Georg Bauhaus
2009-07-30  7:52             ` fft1976
2009-07-30  8:34               ` Ludovic Brenta
2009-07-30 16:10               ` Georg Bauhaus
2009-07-30 17:09                 ` fft1976
2009-07-30 17:20                   ` Pascal Obry
2009-07-30 17:28                     ` fft1976
2009-07-30 17:47                     ` Isaac Gouy
2009-07-31 10:48                       ` Georg Bauhaus
2009-07-30 17:23                 ` Ludovic Brenta
2009-07-30 17:59                 ` Isaac Gouy
2009-07-30 19:38                   ` fft1976
2009-07-30 21:44                     ` Isaac Gouy
2009-07-30 22:14                       ` Paul Rubin
2009-07-31 10:27                         ` Georg Bauhaus
2009-07-31 11:13                     ` Georg Bauhaus
2009-07-31 11:29                   ` Georg Bauhaus
2009-07-31 16:38                     ` Isaac Gouy
2009-07-30 16:25             ` Isaac Gouy
2009-07-30 12:28     ` Colin Paul Gloster
2009-07-30 11:49       ` Martin
2010-03-23 12:31 ` balson
2010-03-23 12:56 ` balson
2010-03-23 13:24   ` Georg Bauhaus
2010-03-23 15:05     ` Maciej Sobczak
2010-03-23 17:52       ` Georg Bauhaus
2010-03-24  6:33       ` Martin Krischik
2010-03-24  8:31         ` Maciej Sobczak
2010-03-23 16:50   ` Warren
2010-03-23 20:29     ` Patrick Scheible
2010-03-24 15:07       ` Warren
2010-03-24 21:11         ` Patrick Scheible
2010-03-24 21:27           ` Pascal J. Bourguignon
2010-03-24 22:14             ` Adam Beneschan
2010-03-24 23:15               ` Patrick Scheible
2010-03-24 23:24                 ` Adam Beneschan
2010-03-24 23:28                 ` Patricia Shanahan
2010-03-25  1:52                   ` John B. Matthews
2010-03-25 16:42               ` Andrew Haley
2010-03-26 23:54               ` Pascal J. Bourguignon
2010-03-24 21:36         ` Adam Beneschan
2010-03-26  7:58           ` Martin Krischik
2010-04-12 11:03           ` Ole-Hjalmar Kristensen
2010-03-24  6:28     ` Martin Krischik
2010-03-24 15:10       ` Warren
2010-03-25  2:19         ` Mike Sieweke
2010-03-25 13:48           ` Robert A Duff
2010-03-25 15:42       ` Colin Paul Gloster
2010-03-26 15:54     ` blmblm
2010-03-26 19:18       ` Warren
2010-03-27  0:03         ` Pascal J. Bourguignon
2010-03-23 17:12   ` J-P. Rosen
2010-03-23 17:41     ` Jim Balson
2010-03-23 17:54       ` Pascal Obry
2010-03-23 18:34         ` jpwoodruff
2010-03-23 20:34           ` Patrick Scheible
2010-03-23 20:33         ` Patrick Scheible
2010-03-23 20:39           ` Pascal Obry
2010-03-24  6:24           ` Martin Krischik
2010-03-23 19:33       ` Adam Beneschan
2010-03-23 22:02         ` Mensanator
2010-03-31  6:55         ` David Thompson
2010-03-31  8:08           ` Martin Krischik
2010-03-24 15:15       ` Warren
2010-03-25 15:46       ` Colin Paul Gloster
2010-03-27  0:53       ` Andrea Taverna
2010-03-27  6:19         ` Gautier write-only
2010-03-23 17:31   ` Patrick Scheible
  -- strict thread matches above, loose matches on Subject: below --
2010-03-23 18:57 cbcurl
2010-03-23 20:27 ` John B. Matthews
2010-03-23 21:34   ` Adam Beneschan
2010-03-24  2:08     ` John B. Matthews
2010-03-24 15:23       ` Warren
2010-03-24 16:57         ` Adam Beneschan
2010-03-24 20:00           ` Warren
2010-03-24 20:48             ` Adam Beneschan
2010-03-25 13:45               ` Warren
2010-03-26  8:20                 ` Martin Krischik
2010-03-26 19:21                   ` Warren
2010-03-28 15:07                     ` Martin Krischik
2010-03-29 13:28                       ` Warren
2010-03-26  8:05             ` Martin Krischik
2010-03-26  8:02           ` Martin Krischik
2010-03-26 19:24             ` Warren
2010-03-28 14:54               ` Martin Krischik
2010-03-29 13:31                 ` Warren
replies disabled

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