comp.lang.ada
 help / color / mirror / Atom feed
From: falis@ma.aonix.com (Ed Falis)
Subject: Re: Ada95 Strengths/Weaknesses.
Date: 1999/09/28
Date: 1999-09-28T00:00:00+00:00	[thread overview]
Message-ID: <1104_938481247@DZOG-CHEN> (raw)
In-Reply-To: t7vh8vx6fh.fsf@calumny.jyacc.com

On 27 Sep 1999 19:48:02 -0400, Hyman Rosen <hymie@prolifics.com> wrote:


> Aside from the verbosity of the Ada code (which is apparent even though
> the C++ equivalents aren't written idiomatically), notice that in the
> output code, it is necessary to repeat the types of the things being
> output, even though the ompiler already knows it!

Not necessary.  MDC is using a more verbose idiom than necessary to 
do the job.

> 
> By the way, here's the C++ for your unimplemented third case -

Not quite the same thing as he did.  Below is Ada code that does what
your C++ does. Let's not confuse style and substance (yes, it's still more
verbose, partly because of multi-line routine definitions and your not using
a header file).

- Ed

package Saver is
    type Save_Stuff (Name_Length: Natural) is private;
    
    function New_Save_Stuff (Str: String; Val: Integer) return Save_Stuff;
    
    procedure Put (S: in out Save_Stuff; X: Integer);
    
    function Get (S: Save_Stuff) return Integer;
private
    type Save_Stuff (Name_Length: Natural) is record
        Name: String (1..Name_Length);
        Save: Integer;
    end record;
end Saver;

package body Saver is

    -- This is used because the C++ default access is private, right?
    function New_Save_Stuff (Str: String; Val: Integer) return Save_Stuff is
    begin
        return Save_Stuff'(Str'Length, Str, Val);
    end;
    
    
    procedure Put (S: in out Save_Stuff; X: Integer)is
    begin
        S.Save := X;
    end;
    
    
    function Get (S: Save_Stuff) return Integer is
    begin
        return S.Save;
    end;
end Saver;

with Saver; use Saver;
with Ada.Text_Io, Ada.Integer_Text_Io;
use Ada.Text_Io, Ada.Integer_Text_Io;
procedure Main is
    My_Obj: Save_Stuff := New_Save_Stuff ("My Object", 55);
    Your_Obj: Save_Stuff := New_Save_Stuff ("Your Object", 55);
begin
    Put (My_Obj, 23);
    Put ("The value of my object is "); Put (Get (My_Obj));
    New_Line;
    
    Put (Your_Obj, 46);
    Put ("The value of your object is "); Put (Get (Your_Obj));
    New_Line;
end Main;

    
        
    
> 
> #include <iostream>
> #include <string>
> 
> using namespace std;
> 
> class SaveStuff
> {
> 	string name;
> 	int save;
> public:
> 	Save_Stuff(string n = string(), int s = 0) : name(n), save(s) { }
> 	void put(int x) { save = x; }
> 	int get() const { return save; }
> };
> 
> int main()
> {
> 	SaveStuff my_obj("My Object", 55);
> 	SaveStuff your_obj("Your Object", 55);
> 
> 	my_obj.put(23);
> 	cout << "The value of my object is " << my_obj.get() << endl;
> 
> 	your_obj.put(46);
> 	cout << "The value of your object is " << your_obj.get() << endl;
> }
> 
> 





  reply	other threads:[~1999-09-28  0:00 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-09-27  0:00 Ada95 Strengths/Weaknesses the middleman
1999-09-27  0:00 ` J. David Bryan
1999-09-27  0:00 ` Steve Doiel
1999-09-27  0:00 ` Marin David Condic
1999-09-27  0:00   ` Hyman Rosen
1999-09-28  0:00     ` Ed Falis [this message]
1999-09-28  0:00       ` Hyman Rosen
1999-09-28  0:00         ` Ed Falis
1999-09-28  0:00     ` Robert Dewar
1999-09-28  0:00       ` Preben Randhol
1999-09-28  0:00         ` bill
1999-09-27  0:00           ` Aidan Skinner
1999-09-28  0:00           ` Preben Randhol
1999-09-28  0:00           ` Steve Doiel
1999-09-28  0:00           ` Larry Kilgallen
1999-09-28  0:00   ` Preben Randhol
1999-09-27  0:00 ` David Starner
1999-09-28  0:00   ` Robert Dewar
1999-09-28  0:00     ` David Starner
1999-09-28  0:00       ` Robert Dewar
1999-09-28  0:00         ` Ray Blaak
1999-09-28  0:00     ` David Starner
1999-09-29  0:00       ` Robert A Duff
1999-09-28  0:00   ` the middleman
1999-09-28  0:00   ` Robert Dewar
1999-09-28  0:00     ` GNAT listing file default names (was: Ada95 Strengths/Weaknesses) Larry Kilgallen
1999-09-28  0:00       ` Gautier
1999-09-29  0:00         ` Robert Dewar
1999-09-29  0:00       ` Robert Dewar
1999-09-29  0:00         ` Larry Kilgallen
1999-09-29  0:00           ` Robert Dewar
1999-09-29  0:00             ` Larry Kilgallen
1999-09-30  0:00               ` Robert Dewar
1999-09-28  0:00     ` Code size of Ada ? was Re: Ada95 Strengths/Weaknesses Alfred Hilscher
1999-09-28  0:00       ` Gautier
1999-09-28  0:00       ` David Botton
1999-09-29  0:00       ` Robert Dewar
1999-09-29  0:00         ` Alfred Hilscher
1999-09-29  0:00           ` Robert Dewar
1999-09-30  0:00             ` Alfred Hilscher
1999-09-30  0:00               ` Robert Dewar
1999-09-30  0:00               ` Gautier
1999-09-29  0:00         ` Larry Kilgallen
1999-09-29  0:00           ` Robert Dewar
1999-09-29  0:00           ` Alfred Hilscher
1999-09-29  0:00             ` Robert Dewar
1999-09-30  0:00               ` Alfred Hilscher
1999-09-30  0:00                 ` Gautier
1999-09-30  0:00                   ` Robert Dewar
1999-09-30  0:00                   ` Robert Dewar
1999-09-30  0:00                   ` Robert Dewar
1999-09-30  0:00                 ` Robert Dewar
1999-09-30  0:00                   ` tmoran
1999-09-30  0:00                   ` Ehud Lamm
1999-09-30  0:00                     ` Robert Dewar
     [not found]                       ` <7t2e1l$lqt2@ftp.kvaerner.com>
     [not found]                         ` <37F91D6E.58685CFE@mitre.org>
     [not found]                           ` <7tf7uo$h2b$1@nnrp1.deja.com>
     [not found]                             ` <37FBA978.A86762F1@mitre.org>
1999-10-18  0:00                               ` Robert Dewar
1999-10-19  0:00                                 ` Code size of Ada ? Robert I. Eachus
     [not found]                           ` <7tf7uo <37FBA978.A86762F1@mitre.org>
     [not found]                             ` <5OkO3.2$1e.659@typhoon.nyu.edu>
1999-10-19  0:00                               ` Code size of Ada ? was Re: Ada95 Strengths/Weaknesses Robert I. Eachus
1999-09-29  0:00             ` Gautier
1999-09-29  0:00               ` Ed Falis
1999-09-29  0:00                 ` Gautier
1999-09-29  0:00                 ` tmoran
1999-09-30  0:00               ` Robert Dewar
1999-09-29  0:00             ` Ted Dennison
1999-09-29  0:00           ` Robert Dewar
1999-09-28  0:00     ` David Starner
1999-09-28  0:00       ` Robert Dewar
1999-09-28  0:00       ` Robert Dewar
1999-09-28  0:00         ` David Starner
1999-09-29  0:00           ` Robert Dewar
1999-09-30  0:00         ` Pragma (was Re: Ada95 Strengths/Weaknesses.) Preben Randhol
1999-09-30  0:00           ` Preben Randhol
1999-09-28  0:00       ` Ada95 Strengths/Weaknesses Ted Dennison
1999-09-28  0:00         ` Simon Wright
1999-09-28  0:00       ` Gautier
1999-09-28  0:00         ` David Starner
1999-09-29  0:00           ` Robert Dewar
1999-09-28  0:00         ` Ed Falis
1999-09-28  0:00           ` David Starner
1999-09-29  0:00           ` Robert Dewar
1999-09-28  0:00       ` p.obry
1999-09-28  0:00         ` David Starner
1999-09-28  0:00           ` Richard D Riehle
1999-09-28  0:00 ` Geoff Bull
1999-09-28  0:00 ` Geoff Bull
1999-09-29  0:00   ` the middleman
1999-09-29  0:00     ` Robert A Duff
replies disabled

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