Live data from Hacker News

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

learn.adacore.com

21–30 of 72 posts

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

#21

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…

There is now, at least with Ada 2012 and GNAT[0][1]. While I'm pretty sure only GNAT has implemented it, I'm not sure if it's actually in the 2012 standard or not. I haven't played with it yet, but it does looks pretty interesting. [0] https://gcc.gnu.org/onlinedocs/gcc-4.9.4/gnat_ugn_unw/Perfor... [1] https://blog.adacore.com/uploads/dc.pdf

PTC also supports Ada 2012.

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

#22

Earlier quoted context omitted.

Accesses - pointers - are automatically nulled when declared. So you won't silently screw up who-knows-what with an uninitialized access, though yeah, it's not perfectly safe.

I didn't mean pointers/access-types, I meant ordinary integer-type locals.

You can put a pragma Warning_As_Error ("never assigned"); or the respective compiler switch on GNAT.

Other compilers have similar switch.

Heck even C and C++ have them, although few make use of them.

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

#23
post #19

I used Ada (first Ada95, later Ada2005) while working on the GPS program, before leaving aerospace and taking on work using Java. I found the Java type system to be horrendous in comparison. Much better employment potential, though...

That is one reason why I never liked C and C++ was a better option when coming from Turbo Pascal 6.

Although Turbo Pascal isn't Ada, it did allow for a similar approach with stronger types, which C++ also kind of supports (but C compatibility spoils it).

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

#26
post #22

Earlier quoted context omitted.

I didn't mean pointers/access-types, I meant ordinary integer-type locals.

You can put a pragma Warning_As_Error (" never assigned "); or the respective compiler switch on GNAT. Other compilers have similar switch. Heck even C and C++ have them, although few make use of them.

Pragma Initialize_scalars for the win. But at runtime.

And if you can afford it, Codepeer (static analysis) finds most of the ones the compiler doesn't find. And then if you can live with the Spark subset, you get proof of initialization in 'bronze' mode :-).

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

#27
post #22

Earlier quoted context omitted.

I didn't mean pointers/access-types, I meant ordinary integer-type locals.

You can put a pragma Warning_As_Error (" never assigned "); or the respective compiler switch on GNAT. Other compilers have similar switch. Heck even C and C++ have them, although few make use of them.

Also, I think Ada is fully memory-safe but for initialization. That is to say, the only way in which it's not memory-safe, is regarding uninitialized variables. (That's assuming of course that you don't disable checks.)

I'm not sure if it lets you shoot yourself in the foot regarding invalid type conversions, misuse of unions, that kind of thing.

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

#30
Wow, reading through some of these examples, it’s pretty clear where VHDL got it’s syntax! I think I do recall some relation between it and Ada, but it’s almost uncannily close. (Looking up now, it was apparently a requirement for it to be based as much as possible on Ada).
Post reply on HN