comp.lang.ada
 help / color / mirror / Atom feed
From: dewar@merv.cs.nyu.edu (Robert Dewar)
Subject: Re: CRC in Ada?
Date: 1997/03/19
Date: 1997-03-19T00:00:00+00:00	[thread overview]
Message-ID: <dewar.858769863@merv> (raw)
In-Reply-To: 332F5CC8.6D7C@worldnet.att.net


Michael said

<<So yes, I DID feel compelled to use an Ada 83 I/O package. I don't think my
  employer would have much appreciated my spending half a day chasing down
  some C file I/O routines to improve the throughput of my test program.>>

No, you felt compelled to *misuse* an Ada 83 I/O package and write highly
non-portable code that relied on the inner workings of sequential_io in
your particular implementation. OK, if you lacked the knowledge to write
the trivial pragma Import for the appropriate C routine (I assume this
if it would have taken you half a day), then you may have been stuck, and
generating this solution may have been the best you could do.

But it was NOT the right solution in Ada, since it did not meet the spec
of the problem except by accident. You cannot expect to do everything in
Ada. Suppose I tell you to write an Ada program that plays a tune on the
speaker.

You have around a C callable routine called Play_Tune that does exactly
what you want, but instead you write a hairy piece of Ada that uses
address clauses to directly address the memory mapped IO port for the
speaker, and write loops with the right frequencies to play the tune.

Your solution is all Ada. Is it therefore superior? no it is perfectly
horrible, and we assume no one would make such a mistake. But your approach
was a (much less obvious and not nearly so horrible) example of the same
mistake.

The fact of the matter is that there WAS no suitable routine in the Ada 83
IO library to solve your problem, just as there is no Play_Note routine.
When you have this situation, then you use pragma Interface, that is what
it is for!

Now in Ada 95, we have Stream_IO which is suitable for solving your problem,
and comparisons of comaprable code using Stream_IO with corresponding C code
are much more meaningful, but it still may be appropriate to use pragma
Interface.

In London a couple of years ago, I gave a talk "Sleeping with the Enemy",
and the theme was that the attitude that C and C++ and ??? are horrible
languages and that you must never go near them is a counter productive
one for Ada programmers. On the contrary, there is lots of useful stuff
there, and a competent Ada programmer knows when and how to take advantage
of it. Note that of course the C or C++ programmer who has a similar
view of Ada (horrible language, don't want to go near it, don't know,
don't want to know) is similarly hobbling themselves.


<<Certainly not Ada versus C, but definitely
  one compiler versus another compiler.
  Pick your I/O package and your language, and 18 minutes versus 27
  seconds to read
  the same file certainly tells you something. HIS compiler (which happens to be
  C++) has buffered file I/O. MY compiler (which happens to be Ada 83) does not
  buffer file I/O>>.

Nope. That misses the point again, you are not comparing one compiler with
another, but rather two completely different solutions, one using a library
routine appropriate to the job, with another solution using an entirely
inappropriate library routine. It would not surprise me at all if the
difference you see, a factor of 30, has nothing at all to do with buffering,
but rather is a natural consequence of the implementation approach for
sequential_IO, which is undoubtedly written to be reasonable for correct
use of the package, and which may well be slow for this clear misuse.

Just to get a bit of a feel for what I mean by sequential_IO being at
a different level of abstraction from the C getchar, look at the following
little bit of code in GNAT's Ada.Sequential_IO.Read:

      --  For non-definite type or type with discriminants, read size and
      --  raise Program_Error if it is larger than the size of the item.

      if not Element_Type'Definite
        or else Element_Type'Has_Discriminants
      then
         FIO.Read_Buf

Now, given a macro substitution approach to generics, it is likely that
this code is optimized away, but in a shared generic approach, it is 
likely to be a real test, and it is certainly a test that would not 
conceivably be present in the C routine.

Does this mean that sequentio_Io is less efficient than the C routine,
no! It means that they are doing different kinds of things. 

If someone compares the peformance of log in C and sqrt in Ada and
tries to draw conclusions about the efficiency of languages, libraries
or compilers from such a comparison, we would immediately see it as
absurd. Comparing getchar in C with sequential_IO.get in Ada is only
slightly less absurd!





  reply	other threads:[~1997-03-19  0:00 UTC|newest]

Thread overview: 143+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-03-02  0:00 CRC in Ada? Dr. John B. Matthews
1997-03-03  0:00 ` Tom Moran
1997-03-03  0:00 ` David Brown
1997-03-04  0:00 ` David L Brown
1997-03-04  0:00   ` Robert Dewar
1997-03-05  0:00   ` Stephen Garriga
1997-03-05  0:00     ` Larry Kilgallen
1997-03-05  0:00       ` Robert A Duff
1997-03-05  0:00         ` Larry Kilgallen
1997-03-06  0:00           ` Robert A Duff
1997-03-06  0:00             ` Robert Dewar
1997-03-06  0:00             ` Robert Dewar
1997-03-06  0:00             ` Robert Dewar
1997-03-09  0:00               ` Dr. John B. Matthews
1997-03-06  0:00             ` Larry Kilgallen
1997-03-06  0:00           ` Fergus Henderson
1997-03-06  0:00             ` Larry Kilgallen
1997-03-06  0:00               ` Robert A Duff
1997-03-07  0:00                 ` Larry Kilgallen
1997-03-07  0:00                   ` Robert A Duff
1997-03-07  0:00                   ` Tom Moran
     [not found]                     ` <1997Mar7.202252.1@eisner>
1997-03-08  0:00                       ` Robert Dewar
1997-03-09  0:00                         ` Geert Bosch
1997-03-11  0:00                           ` Robert Dewar
1997-03-12  0:00                             ` Mats Weber
1997-03-12  0:00                               ` Robert Dewar
1997-03-10  0:00                     ` Dr. John B. Matthews
1997-03-10  0:00                     ` Robert Dewar
1997-03-10  0:00                       ` Tom Moran
1997-03-12  0:00                         ` Robert Dewar
1997-03-10  0:00                   ` Jim Balter
1997-03-07  0:00                 ` Robert Dewar
1997-03-10  0:00               ` Jim Balter
1997-03-06  0:00             ` Robert Dewar
1997-03-10  0:00           ` David Brown
1997-03-12  0:00             ` Robert Dewar
1997-03-10  0:00           ` Tarjei Jensen
1997-03-10  0:00             ` Robert Dewar
1997-03-10  0:00             ` Robert Dewar
1997-03-10  0:00               ` Graham Hughes
1997-03-11  0:00                 ` Robert Dewar
1997-03-11  0:00                   ` Graham Hughes
1997-03-12  0:00                     ` Robert Dewar
1997-03-11  0:00           ` Mark & Zurima McKinney
1997-03-12  0:00           ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-12  0:00           ` Robert I. Eachus
1997-03-13  0:00           ` Jon S Anthony
1997-03-13  0:00             ` Robert Dewar
1997-03-14  0:00               ` Jim Balter
1997-03-14  0:00           ` Jon S Anthony
1997-03-15  0:00             ` Dr. John B. Matthews
1997-03-15  0:00             ` Robert Dewar
1997-03-17  0:00           ` Jon S Anthony
1997-03-06  0:00       ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-07  0:00       ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-07  0:00         ` Robert Dewar
1997-03-08  0:00           ` Robert A Duff
1997-03-10  0:00           ` Jim Balter
1997-03-11  0:00             ` Robert Dewar
1997-03-11  0:00               ` Jim Balter
1997-03-11  0:00                 ` Robert Dewar
1997-03-12  0:00                   ` Jim Balter
1997-03-14  0:00                     ` Richard A. O'Keefe
1997-03-14  0:00                       ` Jim Balter
1997-03-06  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-06  0:00     ` Larry Kilgallen
1997-03-09  0:00       ` Robert Dewar
1997-03-06  0:00     ` Graham Hughes
1997-03-06  0:00       ` Robert Dewar
1997-03-07  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-07  0:00     ` Robert Dewar
1997-03-08  0:00       ` Fergus Henderson
1997-03-10  0:00       ` Jim Balter
1997-03-11  0:00         ` Robert Dewar
1997-03-11  0:00           ` Jim Balter
1997-03-12  0:00             ` Robert Dewar
1997-03-12  0:00               ` Jim Balter
1997-03-14  0:00                 ` Samuel Mize
1997-03-11  0:00           ` Jim Balter
1997-03-11  0:00             ` Robert Dewar
1997-03-12  0:00               ` Jim Balter
1997-03-07  0:00   ` David Brown
1997-03-07  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-10  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-10  0:00     ` Robert Dewar
1997-03-10  0:00       ` Jim Balter
1997-03-11  0:00         ` Robert Dewar
1997-03-11  0:00           ` Jim Balter
1997-03-11  0:00             ` Robert Dewar
1997-03-12  0:00               ` Jim Balter
1997-03-11  0:00       ` Fergus Henderson
1997-03-10  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-11  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-12  0:00   ` Jim Balter
1997-03-12  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-12  0:00   ` Ole-Hjalmar Kristensen FOU.TD/DELAB
1997-03-04  0:00 ` Stephen Garriga
1997-03-04  0:00   ` Robert Dewar
1997-03-05  0:00     ` Stephen Garriga
1997-03-15  0:00     ` Michael & Amy Hartsough
1997-03-16  0:00       ` Robert Dewar
1997-03-16  0:00         ` Michael & Amy Hartsough
1997-03-16  0:00           ` Robert Dewar
1997-03-18  0:00             ` Michael & Amy Hartsough
1997-03-19  0:00               ` Robert Dewar [this message]
1997-03-20  0:00                 ` Michael & Amy Hartsough
1997-03-22  0:00                   ` Robert Dewar
1997-03-24  0:00                     ` Sequential IO on OpenVMS (was: CRC in Ada?) Ken Garlington
1997-03-24  0:00                       ` Larry Kilgallen
1997-03-22  0:00                   ` CRC in Ada? Mark & Zurima McKinney
1997-03-22  0:00                     ` Robert Dewar
1997-03-21  0:00                 ` Tom Moran
1997-03-23  0:00                   ` Robert Dewar
1997-03-23  0:00                     ` Tom Moran
1997-03-24  0:00                       ` Portable Code (was: CRC in Ada?) Larry Kilgallen
1997-03-24  0:00                     ` CRC in Ada? Robert A Duff
1997-03-24  0:00                       ` Larry Kilgallen
1997-03-24  0:00                         ` Robert A Duff
1997-03-24  0:00                       ` Robert Dewar
1997-03-24  0:00                       ` Robert A Duff
1997-03-25  0:00                     ` Robert I. Eachus
1997-04-01  0:00                 ` David Emery
1997-03-04  0:00   ` Matthew Heaney
1997-03-04  0:00   ` Tom Moran
1997-03-04  0:00     ` Stephen Garriga
1997-03-07  0:00   ` John Apa
1997-03-04  0:00 ` Jon S Anthony
1997-03-05  0:00   ` Robert Dewar
1997-03-05  0:00 ` Laurent Pautet
1997-03-05  0:00 ` David C. Hoos, Sr.
1997-03-06  0:00 ` Jon S Anthony
2013-11-14 17:39 ` david
2013-11-14 18:55   ` Adam Beneschan
2013-11-14 19:35   ` tmoran
2013-11-14 20:09   ` Dmitry A. Kazakov
2013-11-14 20:40   ` John B. Matthews
  -- strict thread matches above, loose matches on Subject: below --
1997-03-13  0:00 tmoran
1997-03-13  0:00 ` Robert Dewar
1997-03-14  0:00   ` Tom Moran
1997-03-14  0:00   ` Joakim Olsson
1997-03-15  0:00   ` Tom Moran
1997-03-14  0:00 ` Richard A. O'Keefe
1997-03-14  0:00 ` Jon S Anthony
replies disabled

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