re: Reasons for loving Ada. #1: strong typing VIEW POST

VIEW FULL DISCUSSION
 

Thanks for writing this article, Riccardo.

I have so many questions:

What kinds of projects do you write in Ada? Do you always use Ada or is it a special tool for specialized requirements?

Why should someone reading dev.to learn Ada? Most of us are doing some form of webdev. Does Ada have a place on the web?

Is there a good book for experienced devs who want to learn a little Ada?

Where does Ada excel? It seems to be used mostly for large systems that need to work correctly (avionics, medical equipment, air traffic control, etc.) but are there less publicized uses where it's really good? For example, is anyone converting security sensitive C/C++ in operating systems into Ada?

Do you write Ada in an IDE? If so, which one? How about your compiler? I hear the free tools are not so great and the commercial tools are expensive. Thoughts?

I understand if you can't answer all these questions or if you are planning to answer them in future posts.

Cheers.

 

Why should someone reading dev.to learn Ada?

To keep you out of the debugger more.

Most of us are doing some form of webdev. Does Ada have a place on the web?

You can use Ada for webstuff, just like people have used C and C++ for it. For example:

github.com/stcarrez
github.com/faelys/markup-ada
github.com/faelys/lithium3 - CMS
youtube.com/watch?v=xxbAiuZydPE&t=14s < Ada on Rails - not open to the public though :/

Is there a good book for experienced devs who want to learn a little Ada?

adaic.org/learn/materials/ - use the Distilled book and grab the extras for 2005 and 2012 from the reference manuals.

Where does Ada excel?

Anywhere.

It seems to be used mostly for large systems that need to work correctly (avionics, medical equipment, air traffic control, etc.) but are there less publicized uses where it's really good?

Ada scales well. I've done a lot of small applications without any trouble. Embedded can be small or large, again, it scales well. Embedded is just one area where Ada can be used.

For example, is anyone converting security sensitive C/C++ in operating systems into Ada?

Possibly.

Do you write Ada in an IDE? If so, which one? How about your compiler? I hear the free tools are not so great and the commercial tools are expensive.

You can use a text editor or an IDE, although the quality of IDE's for Ada vary. The commercial Ada tools have always been expensive, but GNAT from the FSF under GCC is free and you can release stuff closed source commercial if you like.

 

While you wait for Riccardo to chime in, I think I can answer some of your questions.

Ada is general-purpose but is not that comfortable for quick, dirty code. I find it excels when you have anything that 1) needs tasking (which is built-in and very high-level, but still efficient, mapped to native threads usually), or 2) is medium-size (let's say, once you need to separate sources into modules). I personally use it for anything that I would do otherwise in C++ instead of python/bash; to me is a safer C++ replacement.

Why learn it: since it mostly forces you to do things right, and write proper specifications (headers are mandatory, and not pre-processed but compiled) when coding in other languages you tend to write better, more structured code, and realize issues that Ada detects and fly over other compilers. You start to miss ranged types everywhere.

There are libraries for the web (check AWS, not the Amazon one) but I would consider it overkill and perhaps cumbersome; although Ada can be interfaced easily with C it requires writing bindings and there are not many libraries, so it's tedious and not easy for the novice. Others may disagree here.

Ada excels at early bug detection. The author's point on debug time is spot-on in my experience. Firing the debugger is the exception rather than a usual step. Also at tasking (already said that). Also, if you're formally-minded, the SPARK proving tools might be your cup of tea. No experience there on my part, but I've seen interesting projects (check Tokeneer/Crazyflie+Spark). In general, my feeling is that of a safer C++, so you might say it's good for the same things (developments that need efficiency, modern features), with a caveat: there are not so many libraries, so I would consider it specially when the bulk of the code is going to be newly written (in Ada).

For a "modern" IDE I'd recommend Gnat GPS (it's free with the GPL edition of the compiler). I say "modern" because it's miles behind e.g. CLion or IntelliJ (also much much lighter), but it's serviceable. A lightweight alternative would be multi-language Geany. Vim/Emacs, if that's your way. The compiler uses gcc as backed so tools can understand the generated object code.

About price, it's true that there are two extremes: the GPL version of Gnat is free for GPL projects, but is (I hear) very expensive for closed developments. However, the FSF-maintained version is very well curated in Debian, although it's a bit behind the privately developed/supported Gnat Pro (not by much).

Hope this helps! Cheers.

 

Thanks for the reply. Those are really great answers.

I've read a bit about Ada and read a whole book on Spark but I've never done a project in either. Do you (or anyone) have an idea how fast you can write a project in Ada vs C/C++?

For example, Let's say I wanted to write a clone of TrueCrypt/VeraCrypt for Debian without looking at the source. Let's further assume that I'm equally proficient in Ada and C/C++. I'm trying to get an idea of how much quality do I need to require from the code to justify the effort of writing in Ada. Does that make sense?

I imagine could quickly pound out a buggy version in C/C++. But the fastest version I could make in Ada would take longer and have fewer bugs than the C/C++ version. And then all the way at the other extreme of quality, I imagine that if I wanted 0.1 defects per KLOC, I could get there faster in Ada than I could in C/C++ (if I could ever get there at all). And at some point, as we move to fewer and fewer defects, those lines cross. Do you (or anyone) have any idea where that might be?

In other words, how much do I need to care about quality to make it worth using Ada? Or is that not true at all? Maybe once you know Ada well, you can write as fast or faster than in C/C++ and lower defect rates are a happy side effect of using the language?

Also, does the equation change if we trade C/C++ with something safer like Java?

Let's see I get the gist of your question.

For an equally proficient Ada/C++ programmer I'd say Ada development speed is the same if not faster. Ada is a bit more verbose, but with a completion editor that's mostly moot, and in any case I feel it would be offset by the gains in debugging time. Ada is not foolproof though, and if you carelessly start to play with pointers you will lose sleep over the same kind of memory corruption errors (I must check Rust for precisely that reason). Dynamic memory management is similar to C++, but using standard containers you can avoid most problems (same as in C++, but still Ada containers have extra checks).

Related: Ada use of the stack is far superior (with its unconstrained/indefinite types), so you can avoid pointers in much more places that would require them in C++. I'd say this is the most jarring part for programmers coming from C/C++, since it has not really an equivalent there (to my knowledge).

If Java enters the picture: you lose somewhat on the efficiency department, but I guess unless doing real-time it won't be a problem. Also, you trade memory corruption for memory leaks in my experience (but I'm not as experienced in Java as in Ada). However, my personal dilemma would mostly be Ada vs Java; I avoid C/C++ if I can (there's too much of it anyway where I cannot choose).

To summarize, if you're equally proficient in Ada/C++/Java:

If a compiled language is a must: Ada unless you need lots of 3rd party libraries that would take a long time to bind/replicate in Ada; in that case C++ with most warnings on. (Gnat has an automatic C binding generator but in my (old) experience it was not yet 100% there).

If interpreted is OK: Java if 3rd party libs needed, Ada if tasking is involved, otherwise down to personal preference (Ada in my case).

Also, another factor against Ada is that the community is (much) smaller, if you want to attract collaborators. On the other hand, there is people very devoted to Ada (but I'd say you lose chances anyway, if only because of numbers).

So, again: Ada if self-contained development, Java if I need many libs, C/C++ if the project is already using it. In your particular example of Truecrypt... if for fun, Ada, but checking the crypto/disk needs first.

Ada is not foolproof though, and if you carelessly start to play with pointers you will lose sleep over the same kind of memory corruption errors (I must check Rust for precisely that reason).

Please do, it would be awesome if someone could debunk them and prove Ada to be superior after all their hot air :)

As for dev speed, the only place where you will slow down is designing thick bindings to C and C++ libs. Tedious isn't the word.

However, my personal dilemma would mostly be Ada vs Java; I avoid C/C++ if I can (there's too much of it anyway where I cannot choose).

Java is pretty bad, IMO, spaghetti code with all the patterns, really hard to follow.

Please do, it would be awesome if someone could debunk them and prove Ada to be superior after all their hot air :)

Hehe. Do you think though there is no substance there? From my superficial reads they get rid of a whole class of errors with the "ownership" idea. Although I don't really grasp the implications yet.

Java is pretty bad, IMO, spaghetti code with all the patterns, really hard to follow.

Certainly the lack of specifications are a step back from Ada. Interfaces mitigate it to some extent, although then one may get lost in the hierarchies; however the new shorthand notation for lambdas and reference functions for callbacks and single-method singletons goes a looong way in terms of local clarity and boilerplate reduction. I couldn't go back to Java 7. But then, that's also the merit of the tools, besides the language itself.

Anyway, I would consider Java instead of Ada mostly for reasons of libraries/community, rather than the language itself.

Hehe. Do you think though there is no substance there? From my superficial reads they get rid of a whole class of errors with the "ownership" idea. Although I don't really grasp the implications yet.

I have no idea, I've only really checked on the whole syntax of the language and it's not for me. But they do have this arrogance going on basically saying that everything should be rewritten in Rust and whenever you mention something they say "Rust has that" and then you find that it's in the library, not the language.

Anyway, I would consider Java instead of Ada mostly for reasons of libraries/community, rather than the language itself.

This is why we need more people working on libs for Ada, so people pick Ada rather than something else.

As for the tooling/libs on Java, yeah, they have loads, but Sun paid universities and company's millions for them to use the language. Plus, forcing everything into a class is coming back to bite them, this is why I think so many people are jumping on the FP bandwagon, there'll come a time when people think forcing everything into a function is bad.

 

Regarding the lack of bindings for the Web, look at the excellent project Swagger Ada: blog.vacs.fr/vacs/blogs/post.html?...

As Stéphane Carrez ends his post: "The APIs.guru lists more than 550 API descriptions from various providers such as Amazon, Google, Microsoft and many other online services. They are now available to the Ada community!"

Excellent, thanks! Also, wasn't there something similar to generate SOAP bindings in AWS? Here, I found it: docs.adacore.com/aws-docs/aws/usin...

I did not know of this binding generator, although it's the work of colleagues... thanks for pointing that out!

code of conduct - report abuse