Live data from Hacker News

Introduction to Ada

learn.adacore.com

71–80 of 193 posts

Re: Introduction to Ada

#71
post #60

Fun fact GNAT (GCC Ada front-end) will use a biased representation for range type when packing tight: with Ada.Text_IO; use Ada.Text_IO; procedure T is type T1 is range 16..19; type T2 is range -7..0; type R is record A : T1; B,C : T2; end record; for R use record A at 0 range 0 .. 1; B at 0 range 2 .. 4; C at 0 range 5 .. 7; end record; X : R := (17,-2,-3); begin Put_Line(X'Size'Image); -- 8 bits end T;

For those not familiar with Ada and bit representations, the compiler is exploiting the fact that types in Ada can have constraints that limit their size. T1 is a type of integer ranging from 16 to 19 (inclusive). Thus, it can only be four distinct values (16, 17, 18, 19). Two bits is enough to represent these four distinct values and thus the binary representation of the type (in record R) can be reduced to 2 bits.

I heard that the only reason Ada had an "Integer" type as opposed to just have range types with user provided bounds was because of String index needing it - String is just a standard array of character in Ada.

Re: Introduction to Ada

#72
post #10

Earlier quoted context omitted.

One of the "Steelman" requirements that Ada was built to satisfy was that any program should be able to be represented with a subset of ASCII that would be compatible with the largest range of terminals, teletypes, and punched cards as possible. Less relevant today, but that's why Ada has so many keywords in it's syntax.

You should count up how many keywords C++ has, then count the number in Ada.

Assuming I counted correctly,

Ada 2012 has 73 reserved words: http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-2-9.htm...

C++ 20 has 97 keywords: https://en.cppreference.com/w/cpp/keyword

Re: Introduction to Ada

#74

I'd be very interested in someone with substantial experience in Ada/Spark providing some insight: * Why did Ada not manage to get a significant foothold outside of some small domains? * What's great, what's not so great about it? * How "modern" does the language feel, including the tooling, documentation, etc? Specifically Spark 2014. ( I see a LSP server and VSCode plugin, for example) * Spark2014 seems to be open…

I don't have extensive experience but learned it a few years ago and believe I can answer some your questions. This is subjective, others might disagree or perhaps add their own experiences.

> Why did Ada not manage to get a significant foothold outside of some small domains?

Probably mostly due to licensing issues. Ada has a runtime that you basically have to use and the most complete AdaCore version forces you to release executables under GPL. The FSF version is less complete (many libraries are missing) and allows you to use the much more permissive mGPL version. However, it always lags behind the version from AdaCore and many developers in the past were scared away by the licensing issues.

Other reasons often mentioned:

- Ada has a certain (perceived) background in the US military and aviation industry, which some people don't like.

- Ada is a very complete language and not easy to learn. The syntax is special, in that it specifies each construct on its own and re-uses keywords.

- Overuse of pragmas and "glued on" Unicode string handling

> What's great, what's not so great about it?

Great: It's an extremely fast and safe general systems language suitable for all kinds of programs. It allows high level and extremely low level programming and is suitable for embedded programming.

Not so great: The type constraints for generics are not as expressive as they could be. Aliasing rules ("pointers") are stricter than they would need to be. There are a few oddities with anonymous vs. named types to watch out for.

> How "modern" does the language feel, including the tooling, documentation, etc? Specifically Spark 2014.

Tooling and documentation is excellent, thanks to AdaCore and several good books, as well as the official Ada reference. The language does not "feel" modern, because many libraries are old and appear to be outdated. In reality, old Ada code will just compile and run so there is no need to constantly update and maintain libraries.

> Spark2014

Can't answer that question.

> Are there any close alternatives that are production ready?

The GNAT Ada ecosystem mostly maintained by AdaCore is as production ready as a language could be. AdaCore expect you to buy a commercial license if you're doing safety critical work. As for other compilers, that depends on the vendor and most of them do not support the latest Ada standard.

Re: Introduction to Ada

#75
post #38

One thing I liked about Ada is that the authors of the language also wrote why they choose things the way they are, what was rejected, etc... Their is a document about this called "The Ada Rationale" available on the web: http://www.ada-auth.org/standards/rationale12.html I did contribute the HTML version of the Ada 1995 Rationale (first language revision) back in the day: https://www.adaic.org/resources/add_content/…

It actually quite common in ISO processes, there are similar documents for C and C++ language revisions.

Re: Introduction to Ada

#76

Looks like a good tutorial, but it doesn't go into much depth on memory-management. The More About Types section has a little. It mentions that automated reference-counting is available through the GNATCOLL library, which seems to have since been broken apart into three different packages [0], so it now resides in gnatcoll-core [1]. Can anyone comment on memory-management in Ada? [0] https://github.com/AdaCore/gnatco…

Besides the sibling comment, there is a FOSDEM talk about it.

https://archive.fosdem.org/2016/schedule/event/ada_memory/

Re: Introduction to Ada

#77
post #60

Fun fact GNAT (GCC Ada front-end) will use a biased representation for range type when packing tight: with Ada.Text_IO; use Ada.Text_IO; procedure T is type T1 is range 16..19; type T2 is range -7..0; type R is record A : T1; B,C : T2; end record; for R use record A at 0 range 0 .. 1; B at 0 range 2 .. 4; C at 0 range 5 .. 7; end record; X : R := (17,-2,-3); begin Put_Line(X'Size'Image); -- 8 bits end T;

For those not familiar with Ada and bit representations, the compiler is exploiting the fact that types in Ada can have constraints that limit their size. T1 is a type of integer ranging from 16 to 19 (inclusive). Thus, it can only be four distinct values (16, 17, 18, 19). Two bits is enough to represent these four distinct values and thus the binary representation of the type (in record R) can be reduced to 2 bits.

The type system in Ada was always so nice to use, and it was incredibly useful when using SPARK to really constrain the bounds of your types and make the runtime exception freedom proofs easier. I miss working in Ada, but I don't really miss working on those kinds of projects.

Re: Introduction to Ada

#78

Looks like a good tutorial, but it doesn't go into much depth on memory-management. The More About Types section has a little. It mentions that automated reference-counting is available through the GNATCOLL library, which seems to have since been broken apart into three different packages [0], so it now resides in gnatcoll-core [1]. Can anyone comment on memory-management in Ada? [0] https://github.com/AdaCore/gnatco…

Hello Max! We agree that it's a hole in the current curriculum, that we intend to fill at some stage with the advanced lessons. State of memory management in Ada is: - You have a lot of facilities to stack allocate/not heap allocate tons of stuff that you would heap allocate in pretty much any other low level languages. - When that doesn't cover you, in Ada you're basically at the level of C++: You have refcounted po…

Great answer, thanks.

Re: Introduction to Ada

#79
post #40

I got to use Ada for eight months in 1997, on a co-op at Rockwell-Collins in their General Aviation department. I learned and wrote a lot of Ada and I loved it. When I had to go back to school in the fall, I was no longer interested in writing C++ and it kind of bummed me out to have to use it again.

Ironically what got me into C++ in 1993, was being able to make use of a type system similar to Turbo Pascal's one that I got to love (I was using TP 6/TPW 1.5 by then), alongside "cheap" compilers and widespread availability on home computers.

I just used C for a couple of months before being given a copy of Turbo C++ 1.0 for MS-DOS, and since then I only used C when the option was outside of my control.

It already felt primitive in 1992/1993 vs the alternatives, and so far C17 has hardly changed in that regard.

Re: Introduction to Ada

#80

The original open source Ada83 compiler that grew into GNAT for Ada95 was written in setl. The author of GNU setl has said he would release the source, but we're still waiting. There are binaries here: https://setl.org/setl/bin/ (No NetBSD ones though, forcing us to use emulation) Ada reminds me of spitbol, and setl can be written in spitbol. R K Dewar's spitbol, written in a portable assembly language called MINIMAL…

Interesting. Never heard of SETL before. There is even a Wikipedia entry: https://en.wikipedia.org/wiki/SETL. References 1 and 2 confirm that it was indeed used to implement the first validated Ada compiler. Didn't know that.
Post reply on HN