comp.lang.ada
 help / color / mirror / Atom feed
From: Brad Moore <bmoore.ada@gmail.com>
Subject: Re: Why .ads as well as .adb?
Date: Tue, 11 Jun 2019 08:39:18 -0700 (PDT)
Date: 2019-06-11T08:39:18-07:00	[thread overview]
Message-ID: <4516d350-0076-4dc7-b482-87d5693d3977@googlegroups.com> (raw)
In-Reply-To: <c56a2eda-45d1-4a39-81fd-62067704d702@googlegroups.com>

So far, the discussion has largely attempted to compare the approaches using very abstract analogies, without specific examples (eg books vs software programs).

I think it its probably a good idea to compare some real examples.

Consider a java class from an example of the n-body problem from the Computer Benchmarks Game website;

See https://benchmarksgame-team.pages.debian.net/benchmarksgame/program/nbody-java-5.html

For the comparison, examine the NBodySystem class, which is the bulk of the example, which appears to be a well written java program.

Imagine someone handed you this class and you asked you to write a program that uses it. It takes a bit of reading to pull out the important parts, just to figure out how to use the class. Someone shouldn't have to wade through pages of implementation to figure out how to use the class. This simulation only has data for four planets. Imagine if it were modelling considerably more objects (asteroids, etc) in the solar system. There could be a lot of data to wade through, not to mention code. This is still a pretty simple program, classes in the real world often can be a lot more complex with larger implementations. 

If I were to directly translate that class into Ada, though, I'd likely end up with something like the following package specification.

--  Simulates orbits of the Jovian planets using a simple symplectic-integrator
--
package N_Body_System is

   procedure Reset_Simulation;
   
   procedure Advance (dt : Duration);
   
   function Energy return Long_Float;

end N_Body_System;


Although in Ada I'd want to also define a suitable type for the return object of the Energy function that would describe the units of result. I cannot easily tell by looking at the java example what the units are, and didn't bother digging in to find out. Of course, comments would also be helpful.

Because the N_Body_System is a singleton class in Java, there's no need to create an object for it in Ada, all the implementation details can be placed in the body of the package.

Rather than a constructor as in Java, I provided a Reset_Simulation call, in case someone wanted to rerun the simulation more than once (perhaps to measure a performance average)

To me, this provides a much simpler view for the client programmer. One can likely write a program to run the simulation without even looking at the implementation. If someone wants to understand the implementation, they can look at that if they really want to. I feel that having the language encourage you to intermix the specification and implementation together is really unappealing, from a system engineering point of view, in my opinion.

Brad


  reply	other threads:[~2019-06-11 15:39 UTC|newest]

Thread overview: 88+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-02  0:48 Why .ads as well as .adb? John Perry
2019-06-02  5:42 ` J-P. Rosen
2019-06-02  6:39 ` Dmitry A. Kazakov
2019-06-03  7:35   ` Maciej Sobczak
2019-06-03  7:57     ` J-P. Rosen
2019-06-03 19:49       ` Keith Thompson
2019-06-04  8:03       ` Maciej Sobczak
2019-06-03  8:13     ` Dmitry A. Kazakov
2019-06-03 19:51       ` Keith Thompson
2019-06-03 20:18         ` Dmitry A. Kazakov
2019-06-04  8:24       ` Maciej Sobczak
2019-06-04  9:33         ` Dmitry A. Kazakov
2019-06-05  9:04           ` Maciej Sobczak
2019-06-05 12:48             ` Dmitry A. Kazakov
2019-06-05 17:12               ` G. B.
2019-06-05 18:50                 ` Optikos
2019-06-05 22:57                   ` Randy Brukardt
2019-06-04 22:28         ` Randy Brukardt
2019-06-05  8:28           ` Maciej Sobczak
2019-06-05  9:20             ` J-P. Rosen
2019-06-05  9:28               ` Paul Rubin
2019-06-05 10:11                 ` Niklas Holsti
2019-06-05 12:58                   ` Maciej Sobczak
2019-06-05 14:28                     ` Niklas Holsti
2019-06-06  7:34                       ` Maciej Sobczak
2019-06-06 19:51                         ` Keith Thompson
2019-06-06 20:27                           ` J-P. Rosen
2019-06-06 21:12                         ` Randy Brukardt
2019-06-06 21:17                         ` Randy Brukardt
2019-06-06 22:08                           ` Dennis Lee Bieber
2019-06-07  7:59                           ` Maciej Sobczak
2019-06-07 10:42                             ` alby.gamper
2019-06-07 16:59                               ` Dennis Lee Bieber
2019-06-07 14:10                             ` Brad Moore
2019-06-07 23:37                               ` Paul Rubin
2019-06-08  1:16                                 ` Brad Moore
2019-06-08  7:34                                   ` Simon Wright
2019-06-08 17:44                                 ` G.B.
2019-06-08 21:41                                 ` Keith Thompson
2019-06-09  0:40                                   ` Paul Rubin
2019-06-09 18:56                                     ` Keith Thompson
2019-06-09 20:35                                       ` John Perry
2019-06-09 21:15                                         ` Niklas Holsti
2019-06-09 22:37                                           ` John Perry
2019-06-10  9:01                                             ` Simon Wright
2019-06-10 13:15                                               ` Simon Wright
2019-06-10  9:22                                             ` Niklas Holsti
2019-06-09 21:37                                         ` Simon Wright
2019-06-09 22:40                                           ` John Perry
2019-06-10  9:07                                             ` Simon Wright
2019-06-09 21:46                                         ` Niklas Holsti
2019-06-10 17:11                                         ` Dennis Lee Bieber
2019-06-08  4:57                             ` Randy Brukardt
2019-06-08 23:57                               ` Optikos
2019-06-09  0:43                                 ` Paul Rubin
2019-06-10  8:17                               ` Maciej Sobczak
2019-06-10 19:10                                 ` G.B.
2019-06-10 22:07                                 ` Randy Brukardt
2019-06-11  0:32                                   ` Optikos
2019-06-11 15:39                                     ` Brad Moore [this message]
2019-06-11 16:14                                       ` John Perry
2019-06-11 16:46                                         ` Shark8
2019-06-11 19:29                                           ` John Perry
2019-06-14  6:12                                             ` Brad Moore
2019-06-14 21:51                                               ` John Perry
2019-06-14 16:29                                             ` djakoogler
2019-06-11 18:19                                         ` joakimds
2019-06-11 15:49                                   ` Jeffrey R. Carter
2019-06-07  7:36                       ` Niklas Holsti
2019-06-05 22:41                     ` Randy Brukardt
2019-06-06  3:34             ` Keith Thompson
2019-06-06  7:29               ` Maciej Sobczak
2019-06-06 15:30                 ` John Perry
2019-06-06 15:41                 ` Brad Moore
2019-06-06 19:42                 ` Keith Thompson
2019-06-06 16:37               ` Dennis Lee Bieber
2019-06-02  9:59 ` joakimds
2019-06-02 20:14 ` G.B.
2019-06-03 13:37 ` John Perry
2019-06-03 14:50   ` Niklas Holsti
2019-06-03 19:23     ` John Perry
2019-06-03 21:04       ` Niklas Holsti
2019-06-03 18:51   ` Lucretia
2019-06-03 19:32     ` John Perry
2019-06-03 17:00 ` Jeffrey R. Carter
2019-06-03 18:59   ` Lucretia
2019-06-03 19:29   ` John Perry
2019-06-03 20:00     ` Jeffrey R. Carter
replies disabled

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