comp.lang.ada
 help / color / mirror / Atom feed
* some questions re. Ada/GNAT from a C++/GCC user
@ 1996-03-27  0:00 Bill Newman
  1996-03-27  0:00 ` Robert Dewar
                   ` (5 more replies)
  0 siblings, 6 replies; 80+ messages in thread
From: Bill Newman @ 1996-03-27  0:00 UTC (permalink / raw)


I have been skimming _Ada as a Second Language_ (second edition) and I
have looked at the GNAT documentation.  I am impressed: Ada and GNAT
look like they should do a pretty good job of meeting their design
criteria.  However, before I start planning my next project in Ada :-)
there are a few things I'd like to know..  (I hope against hope that
the tone of the answers will resemble the cross-language comparisons
in _Ada as a Second Language_ more closely than it resembles the
recent C++/Ada flamewar.)

The Ada Programming FAQ pooh-poohs STL, but I like it.  (Yes, I know I
could write my own versions of what I need, but a bunch of Ada
programmers shouldn't need to be told that that's not the ideal
solution.)  This FAQ also says the Booch components library is coming
-- when?

Does GNAT completely implement generics as defined in the standard?
(I ask because I have heard that no compiler, G++ otherwise, has yet
implemented C++ templates completely, and the G++ implementation
caused me lots of hassles before 2.7.x, and still causes some hassles
now.)

I *assume* that GNAT supports exceptions completely since they're an integral
part of the language and I didn't see any disclaimers, but since AFAIK G++
doesn't do them very well, I'd like to double-check: how well does
GNAT do exceptions?

I didn't notice anything about garbage collection in the GNAT docs, so
I assume it doesn't support it.  Will GNAT support GC in the
foreseeable future?

How well does GDB work with GNAT output?  Is it possible to get GDB to
interactively call arbitrary procedures/functions from GNAT-generated
code?  I have been very frustrated by the way that I can't get GDB to
call operator<<(ostream&, const Some_Class&) interactively, which
makes it very painful to inspect the state of a program produced by
G++.  (I do *not* appreciate having to inspect my data raw field by
raw field for every object in a complicated graph.)  Would I have the
same problem when inspecting the state of programs produced by GNAT?

Is there any way in Ada to iterate abstractly over the contents of a 
container, i.e. without writing each loop in a way which depends
strongly on the implementation of the container?  I know I 
could define a container class Foo_Basket_Type which would 
let me do something like
    for I = 1 .. Size(Foo_Basket) loop -- class implemented as array
       Sum := Sum + Bletchery(Element(Foo_Basket, I));
    end loop;
or 
    I : Foo_Basket_Iterator_Type := Head(Foo_Basket);
    ..
    while not Is_Done(I) loop -- class implemented as list
       Sum := Sum + Bletchery(dereference I);
       I := Next(I);
    end loop;
but what I'd really like to is something like 
    for each I in Foo_Basket loop -- don't much care how class is implemented
       Sum := Sum + Bletchery(dereference I);
    end loop;
I understand that in languages like Sather, I could do this without
macros.  In G++ I can come pretty close to this with CPP macros:
    FOR_EACH(i, foo_basket)
      sum += bletchery(*i);
In standard C++ (without the G++ `typeof' operator) I'd write something like
    FOR_EACH(i, Foo_Basket::Iterator, foo_basket)
      sum += bletchery(*i);
I use this idiom a lot -- about once per 40 lines of code in my
current project.  I much prefer it to the alternative of making my
code depend on the implementation of the container.  Is there any way of
doing something like this in Ada?  (I imagine there is, since the
alternatives look unnecessarily difficult to maintain.)
    
Due in part to my problems with GDB mentioned above, my C++ programs
tend to contain a lot of calls to macros MUTTER1, MUTTER2,
etc. defined either as no-op (for low levels of verbosity) or as
   #define MUTTER1(x) do { cerr << mutter_prefix << x << '\n'; } while (false)
so that I can write things like 
   MUTTER1("done with sampling, w = " << w << ", table = " << table);
concisely.  It's my impression that Ada's I/O facilities make it hard
to do trivial things like this concisely.  Is this wrong?  I don't really
want to have to write 
   if (Global_Verbosity >= 1) then
     Write_Mutter_Indent(Global_Mutter);
     Write(Global_Mutter, "done with sampling, W = ");
     Write(Global_Mutter, W);
     Write(Global_Mutter, ", table = ");
     Write(Global_Mutter, Table);
     Write_Line(Global_Error); -- silly typo encouraged by excess verbosity
   end if;
for a simple statement like the one above.

When I make two different instantiations of a generic package with the
same arguments, I understand the compiler treats them formally as two
different packages, which is OK with me.  However, I'd appreciate
knowing the compiler wouldn't actually output two redundant copies of
the corresponding (identical?) machine code, but instead share the
code.  I saw somewhere that the compiler is given considerable freedom
to share one instantiation between several arguments if it thinks it's
appropriate, which is also OK with me.  However, I haven't seen any
guarantee that the compiler won't output redundant copies for
instantiations with identical arguments.  Is there such a guarantee?

Can someone give me an idea what kind of compilation speed I could
expect from GNAT on a 486DX2/66 with 20 Mb of RAM, for projects of
1,000-50,000 lines?  (I'm interested both in the time required for
complete recompilation and in the time required for recompilation
after a trivial local change.)

My examples of `for each' and `mutter' above share a common feature:
I'd like to abstract away a common pattern so that I only need to type
each argument once, and I haven't figured out how to do it in Ada.  I
don't object to the rest of the verbosity I have seen in Ada: I can
see that it might make programs more readable, and since it's checked
by the compiler it shouldn't make programs significantly harder to
maintain.  However, the kind of verbosity required to hand-code
patterns like `for each' and `mutter' does not seem to make code more
readable, and since it is not checked by the compiler I'm afraid it
might cause maintenance problems by making it possible to add bugs by
changing some but not all occurrences of the redundant terms.  Are
there ways (e.g.  in the cases described above, or other cases that I
haven't thought of yet) in which Ada will force me to do this kind of
thing where C++ wouldn't?  If so, is this a bad thing (as I suspect),
or is it a positive feature in some sense that I haven't figured out,
or is it just the price we pay for the benefit of being guaranteed
that no one has abused macros in the program?

I also have a few idle questions about the design and application of
Ada 95, more-or-less unrelated to the question of whether I'll decide
to use it:

Why doesn't Ada 95 allow declarations to be interspersed with ordinary
statements as C++ does?  (Or does it?  _Ada as a Second Language_ is a
big book!)  It seems to me that the C++ approach is a small but
definite win.  Does it interact very badly somehow with all those
guarantees on elaboration order?

Someone remarked -- in this newsgroup recently IIRC -- that macros
were explicitly disallowed in the design goals for Ada (Ada 83?),
since they make programs hard to understand.  I don't remember the
exact wording, but as I remember the key reason was that you would
never know what was a macro and what wasn't without reading the entire
program hunting for macro definitions.  (I searched for `macro' in the
Rationale without success, so I'm just going on speculation and dim
memory here.)  It seems to me that that is a funny objection: most
macro processors these days don't require a characteristic pattern to
introduce macro expansions, but as far as I can tell there's no reason
that you couldn't restrict macro expansion to e.g. patterns preceded
by the keyword `macro'.  Granted, C's macro facilities are fairly
disgusting and inconsistent with the design goals of Ada, but it seems
to me a macro facility (or `generic syntax' facility?) more consistent
with Ada could be useful -- perhaps something closer to Scheme's
`hygienic macros' than to C's macro preprocessor.  Some restrictions
(e.g. only allowing macros to expand into expressions, sequences of
statements, or sequences of declarations, and not into arbitrary textual
strings) and perhaps importing from Lisp the idea that macros are
transformations on patterns of language tokens and expressions, rather
than transformations on patterns of characters) could do a pretty
decent job of discouraging people from writing truly screwy macros
without forbidding useful macros like `For_Each' or (to generalize
`MUTTER') `Write_Sequence' (sending a bunch of items to the same
stream, and using the language's overloading facility to sort out
which version of the Write procedure to call for each).  Would this
have been a good idea, except perhaps that the language is too
complicated already, or would this be a bad idea for some more
fundamental reason?

Finally, I found it intriguing when someone (somewhere in the endless
C++ vs. Ada thread) described a program which used exceptions to
convert runtime errors to `graceful degradation' so successfully that
the program (for fire control?!) continued operating more-or-less
correctly despite numerous bugs.  It seems to me that for the kinds of
programs that I typically work on, that this would require more than
exceptions (perhaps divine intervention?)  but I can imagine that it
would be possible for a program which was conceptually like a bunch of
closed-loop feedback systems, without a lot of state.  Therefore, it's
my guess that the program in question was such a program.  Is that a
sensible guess?  If not, i.e. if this kind of performance would be
possible in a program with lots of state, can someone give me a
pointer to the theory of this kind of thing?  (And are there any
examples of such fault-tolerant programs available on the net?)
(Examples of programs with lots of state include computer operating
systems like UNIX (or Emacs:-), or perhaps an air-traffic control
system which needs to base its output on data up to twenty hours old
regarding flight departure times, radar and weather reports, etc.  An
example of a system without much state would be a translation of a
system of analog radar-guided AA gun controllers directly into
software.)

  Bill Newman
  wnewman@netcom




^ permalink raw reply	[flat|nested] 80+ messages in thread
* Re: some questions re. Ada/GNAT from a C++/GCC user
@ 1996-03-28  0:00 Simon Johnston
  0 siblings, 0 replies; 80+ messages in thread
From: Simon Johnston @ 1996-03-28  0:00 UTC (permalink / raw)


> Bill asked:
>
> The Ada Programming FAQ pooh-poohs STL, but I like it.  (Yes, I know
> I could write my own versions of what I need, but a bunch of Ada
> programmers shouldn't need to be told that that's not the ideal
> solution.)  This FAQ also says the Booch components library is
> coming
>
>   Those opinions do not represent the opinions of all in the Ada
>   community by any means. The STL is a remarkable piece of work in
>   my opinion. There is some very nice work going on at Rensaleer
>   rewriting STL in Ada.

I also like the STL, I also have to use it in C++ development so an
Ada *equivalent* (not necessarily direct port) would be great. I read
a paper recently (can't lay my hand on it now) about implementing the
STL in Ada-95, which although favourable might lead non-Ada people to
believe that an implementation in Ada-95 would be hard, slow,
inefficient and unwieldy. I think such issues should be directly
challanged and lets have an STL-like library ASAP!!

> Does GNAT completely implement generics as defined in the standard?
>
>   Yes
>
> I *assume* that GNAT supports exceptions completely
>
>   You assume correctly
>
> I didn't notice anything about garbage collection in the GNAT docs,
> so I assume it doesn't support it.  Will GNAT support GC in the
> foreseeable future?
>
>   We have no such plans. Several volunteers have mentioned projects
>   to this effect. Perhaps you would like to help in this area!
>
> How well does GDB work with GNAT output?
>
>   Very well. We have used GDB for years to debug GNAT itself, and
>   many of our customers have used it to debug large programs. There
>   are areas where improvements are possible and planned,
>   particularly in the tasking area.
>
>   You assume correctly
>
> I didn't notice anything about garbage collection in the GNAT docs,
> so I assume it doesn't support it.  Will GNAT support GC in the
> foreseeable future?
>
>   We have no such plans. Several volunteers have mentioned projects
>   to this effect. Perhaps you would like to help in this area!
>
> How well does GDB work with GNAT output?
>
>   Very well. We have used GDB for years to debug GNAT itself, and
>   many of our customers have used it to debug large programs. There
>   are areas where improvements are possible and planned,
>   particularly in the tasking area.
>
> Is it possible to get GDB to
> interactively call arbitrary procedures/functions from
> GNAT-generated code?
>
>   Yes.
>
> When I make two different instantiations of a generic package with
> the same arguments, I understand the compiler treats them formally
> as two different packages, which is OK with me.  However, I'd
> appreciate knowing the compiler wouldn't actually output two
> redundant copies of the corresponding (identical?) machine code, but
> instead share the code.
>
>   It is not easy in general to share code. GNAT always generates
>   separate code which results in optimizing time at the expense of
>   space. There are no plans to change this. (Note of course that
>   plans can always be changed by customers with requirements and
>   $$$$)
>
> Can someone give me an idea what kind of compilation speed I could
> expect from GNAT on a 486DX2/66 with 20 Mb of RAM, for projects of
> 1,000-50,000 lines?
>
>   Why not just try it? the cost of a trial copy of GNAT is not
>   expensive! Generally we see compilation speeds of several thousand
>   lines a minute on such machines, but there are many variables.
>
> Robert Dewar
> Ada Core Technologies
>

with StandardDisclaimer; use StandardDisclaimer;
package Sig is
--,-------------------------------------------------------------------------.
--|Simon K. Johnston - Development Engineer (C++/Ada95) |ICL Retail Systems |
--|-----------------------------------------------------|3/4 Willoughby Road|
--|Unix Mail: skj@acm.org                               |Bracknell          |
--|Telephone: +44 (0)1344 476320 Fax: +44 (0)1344 476302|Berkshire          |
--|Internal : 7261 6320   OP Mail: S.K.Johnston@BRA0801 |RG12 8TJ           |
--|WWW URL  : http://www.acm.org/~skj/                  |United Kingdom     |
--`-------------------------------------------------------------------------'
end Sig;




^ permalink raw reply	[flat|nested] 80+ messages in thread

end of thread, other threads:[~1996-04-09  0:00 UTC | newest]

Thread overview: 80+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-03-27  0:00 some questions re. Ada/GNAT from a C++/GCC user Bill Newman
1996-03-27  0:00 ` Robert Dewar
1996-03-28  0:00   ` Norman H. Cohen
1996-03-28  0:00   ` Brian Rogoff
1996-03-29  0:00     ` John G. Volan
1996-03-30  0:00       ` Mike Young
1996-03-30  0:00         ` Ted Dennison
1996-03-31  0:00           ` Mike Young
1996-03-30  0:00       ` Robert A Duff
1996-03-31  0:00         ` Robert Dewar
1996-04-01  0:00           ` Norman H. Cohen
1996-03-31  0:00         ` John G. Volan
1996-03-31  0:00           ` Mike Young
1996-04-02  0:00             ` Glenn H. Porter
1996-04-02  0:00               ` Jonas Nygren
1996-04-02  0:00               ` Robert Dewar
1996-04-03  0:00               ` Geert Bosch
1996-04-03  0:00                 ` Robert Dewar
1996-04-01  0:00           ` Robert A Duff
1996-04-03  0:00             ` Scott Leschke
1996-04-04  0:00               ` AdaWorks
1996-04-01  0:00           ` Bruce.Conroy
1996-04-01  0:00       ` Norman H. Cohen
1996-04-01  0:00         ` Robert A Duff
1996-04-01  0:00           ` Mike Young
1996-04-02  0:00             ` Robert A Duff
1996-04-02  0:00             ` Norman H. Cohen
1996-04-01  0:00         ` Mike Young
1996-04-02  0:00           ` Norman H. Cohen
1996-04-02  0:00           ` David Shochat
1996-04-02  0:00             ` Mike Young
1996-04-02  0:00           ` Robert Dewar
1996-03-28  0:00 ` Ted Dennison
1996-03-29  0:00   ` Adam Beneschan
1996-03-28  0:00 ` Scott Leschke
1996-03-29  0:00   ` Robert A Duff
1996-03-30  0:00     ` Richard Pitre
1996-03-30  0:00       ` Robert A Duff
1996-03-31  0:00         ` AdaWorks
1996-04-01  0:00           ` Robert A Duff
1996-04-01  0:00             ` Ken Garlington
1996-04-01  0:00               ` Robert A Duff
1996-04-02  0:00                 ` Ken Garlington
1996-04-02  0:00                   ` Robert A Duff
1996-04-02  0:00                     ` Ken Garlington
1996-04-02  0:00                       ` Robert A Duff
1996-04-03  0:00                         ` Ken Garlington
1996-04-09  0:00                           ` Matt Kennel
1996-04-03  0:00                         ` David Emery
1996-04-02  0:00                 ` Tucker Taft
1996-04-02  0:00                   ` Felaco
1996-04-02  0:00                     ` Robert Dewar
1996-04-03  0:00                     ` Mark A Biggar
1996-04-01  0:00             ` Norman H. Cohen
1996-04-01  0:00             ` AdaWorks
1996-04-01  0:00               ` Mike Young
1996-04-02  0:00                 ` Robert Dewar
1996-04-02  0:00                 ` AdaWorks
1996-04-01  0:00         ` Richard A. O'Keefe
1996-04-01  0:00           ` Robert A Duff
1996-04-01  0:00         ` Robert Dewar
1996-04-02  0:00       ` Robert I. Eachus
1996-03-29  0:00   ` Robert I. Eachus
1996-03-29  0:00   ` Bill Newman
1996-03-29  0:00 ` Robert A Duff
1996-03-29  0:00   ` Brian Rogoff
1996-04-01  0:00     ` Mark A Biggar
1996-04-01  0:00       ` Robert A Duff
1996-03-30  0:00   ` Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Robert I. Eachus
1996-03-31  0:00     ` Mike Young
1996-03-31  0:00       ` Fergus Henderson
     [not found]   ` <4jlj79$h1k@Nntp1.mcs.net>
1996-04-01  0:00     ` some questions re. Ada/GNAT from a C++/GCC user Robert A Duff
1996-04-02  0:00       ` Kevin Cline
1996-04-02  0:00         ` Robert A Duff
1996-04-01  0:00   ` Iterators (was Re: some questions re. Ada/GNAT from a C++/GCC user) Robert I. Eachus
1996-04-04  0:00   ` some questions re. Ada/GNAT from a C++/GCC user Jon S Anthony
1996-03-30  0:00 ` Simon Wright
1996-04-01  0:00 ` Laurent Guerby
1996-04-01  0:00   ` Robert A Duff
  -- strict thread matches above, loose matches on Subject: below --
1996-03-28  0:00 Simon Johnston

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