Live data from Hacker News

Ada for the C++ and Java Developer [pdf]

learn.adacore.com

41–50 of 72 posts

Re: Ada for the C++ and Java Developer [pdf]

#42

One of my favorite features of Ada 2012 are the design-by-contract checks taken from Eiffel[0]: Preconditions: "a condition or predicate that must always be true just prior to the execution of some section of code or before an operation"[1]. It is up to the caller (client) to set up the preconditions and ensure that they are true before calling the code in question. If any preconditions are not met, it is the fault o…

The problem I’ve seen with trying to add non-static contracts to performance-sensitive languages has been ideological rather than technical.

Specifically, do the language semantics allow a mode where these checks can be turned off? Leaving them on all the time can be a huge performance burden, both directly and in the barriers they add to optimization (while there are potential optimization benefits to exploiting the guarantees of contracts, I don’t think as a practical matter they balance out).

But allowing them to be turned off in “release mode” eliminates much of the benefit in all modes: Developers can no longer assume that their code always runs in a context where the contractual guarantees are met, so they have to guard data integrity or safety critical operations dynamically anyway.

Re: Ada for the C++ and Java Developer [pdf]

#44

One of my favorite features of Ada 2012 are the design-by-contract checks taken from Eiffel[0]: Preconditions: "a condition or predicate that must always be true just prior to the execution of some section of code or before an operation"[1]. It is up to the caller (client) to set up the preconditions and ensure that they are true before calling the code in question. If any preconditions are not met, it is the fault o…

C++20 was supposed to have them, but they were removed on the very last minute, if we are lucky maybe C++23 will get them, but C++26 is most likely, if they ever go forward with them. [1]

For C you can have a look at Frama-C. [2]

D also has DbC. [3]

In case you can target Windows only, VC++ supports SAL Annotations, while not DbC they help to improve code security

[1] - http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p233...

[2] - https://frama-c.com/html/acsl.html

[3] - https://dlang.org/spec/contracts.html

[4] - https://docs.microsoft.com/en-us/cpp/code-quality/using-sal-...

Re: Ada for the C++ and Java Developer [pdf]

#45

One of my favorite features of Ada 2012 are the design-by-contract checks taken from Eiffel[0]: Preconditions: "a condition or predicate that must always be true just prior to the execution of some section of code or before an operation"[1]. It is up to the caller (client) to set up the preconditions and ensure that they are true before calling the code in question. If any preconditions are not met, it is the fault o…

The problem I’ve seen with trying to add non-static contracts to performance-sensitive languages has been ideological rather than technical. Specifically, do the language semantics allow a mode where these checks can be turned off? Leaving them on all the time can be a huge performance burden, both directly and in the barriers they add to optimization (while there are potential optimization benefits to exploiting the…

I guess it's as bounds check and other runtime validity checks integrated in the language. When we upgrade compiler versions, I usually run a global app profile (perf, and internal tools you must have when latency and cpu load are actual product requirements. Every 'new' hot spot is analyzed and if it's a contract, I check whether there's a less costly way to perform it, or if watering down the contract seems OK (usually not). The thing is, a precondition (especially if you went through AoRTE, or silver-level SPARK) can authorize you to aggressively remove all runtime checks (and get far more performant code) 'behind'.

Re: Ada for the C++ and Java Developer [pdf]

#47
post #16

If any Ada users are here, I have question on one section: procedure Main is type Distance is new Float; type Area is new Float; D1 : Distance := 2.0; D2 : Distance := 3.0; A : Area; begin D1 := D1 + D2; -- OK D1 := D1 + A; -- NOT OK: incompatible types for "+" operator A := D1 * D2; -- NOT OK: incompatible types for ":=" assignment A := Area (D1 * D2); -- OK end Main; > The predefined Ada rules are not perfect; they…

I am not an Ada expert, but I came up with this. Please notice that the idea here is not to have the compiler do proper dimensional analysis but simply to avoid the default operator overloading of "*" for the Distance type that also returns a Distance value. Nothing very high-level, as we need to explicitly manipulate the single-component records, but it does the job. with Ada.Text_IO; use Ada.Text_IO; procedure Main…

This is the right way to approach it on my opinion.

Re: Ada for the C++ and Java Developer [pdf]

#48
post #40

Ada seems like a really good language. Is there any reason why it isn't more popular?

My personal reasons as someone who has learned the language quite intensively but ultimately decided not to use it: (i) Vendor lock-in and too much future dependence on Adacore (other commercial Ada compilers do not count as alternatives to me because they are super-expensive), (ii) I can't always use the MGPL and would prefer MIT licenses of important Ada packages, (iii) the user community is split in a weird way be…

As someone who is going all in with Ada, every time I have to reinvent the wheel I plan on releasing it as a MIT licensed library on github. Hopefully if enough Ada programmers do that, we won’t have to worry about it as much.

Re: Ada for the C++ and Java Developer [pdf]

#50
The inclusion of Java in the title is misleading: "For those coming from the Java world: there's no garbage collector in Ada, so objects allocated by the new operator need to be expressly freed." So really, you first need a prerequisite which explains how to program without a garbage collector, but this will have a much greater scope than a book that just teaches you Ada.
Post reply on HN