[ask] how to from c/c++/java to ada ? just for fun

I learn ada just for fun, but I got experience from c-like language a lot,
so I want to learn ada the c/c++/java way

any tutorial? thanks :wink:

2 Likes

The best way is IMO to start a small project. You could take some old program of your own and try to implement it in Ada. Do not forget asking questions about Ada’s programming patterns, since they differ from C/C++/Java. Especially pay attention to Ada’s ability to define scalar user types, avoid predefined types. Another key feature is returning indefinite objects. You do not need malloc(). So avoid pointers. Furthermore, avoid any libraries including the standard one. Ada can be effectively used and learned in its pure form. Once you master Ada you can start using libraries with the knowledge how things works there, should you be asked to implement them. Differently to modern C++ (the old C++ was quite transparent) in Ada you can trace practically any construct down to the machine instructions.
Good luck!

4 Likes

You could try old Advent of Code puzzles. A group of us work on them every year, so you can find solutions on this website, complete with links to GitHub repos, and compare what you might write in C/C++/java with Ada. It’s instructive to compare how an algorithm is implemented differently in different languages.

I did this with Rust a couple of years ago. Interestingly, Ada has a reputation for verbosity, but I found several cases where Rust was more verbose and awkward. And of course Ada’s type system allowed me to do things I can only dream of doing in Rust.

3 Likes

Not a tutorial, but more advice on how to use Ada: describe the problem-space with the type-system, then use that to solve the problem.

4 Likes

There is also this ebook: Ada for the C++ or Java Developer — learn.adacore.com

3 Likes

oh, shit, I didn’t notice it, finally got it, thanks

1 Like

That ebook is very basic. It will show you the equivalent code but it doesn’t cover a lot of problems that you will encounter when going from C++/Java to Ada, especially if you use STL a lot. Also doesn’t cover casting/boxing which many C++/Java developers tend to use.

1 Like

Well if you’re familiar with the STL, you should have no trouble using the Ada container library.

3 Likes

I’d caution that that really depends on how familiar one is with Ada before setting out to use its container library.

  • Ada handles generics very, very differently from C/C++.
  • Ada’s container library offers far fewer features than the STL.
  • Ada’s vocabulary is very different from C/C++: both the use of different words and the use of the same words, but with different meanings.

I was familiar with the STL back in 2017-2018, which was rougjhly when I started with Ada. Admittedly I didn’t use Ada regularly, but it took me quite a while to wrap my head around Ada and its container library.

1 Like

Welcome to the forum! Nice to see a post from the person who had a big influence on the creation of the Ada container libraries.

1 Like

casting/boxing ? If you need casting to convert a malloc returned value, you’re fortunate, in Ada, you spell new Typeand you have a value of the needed type. You want to implement a fancy generic structure (lets says a Red-Black balanced tree with no hardwired leaf type) ? use a generic type/package, and you have what you want. You want to check if Objis in Childclass, then have a variable with the Childclass type ? Just use Child(Obj).

And if you really know what you are doing Ada.Unchecked_Conversioncan be your friend. (But obviously, it shouldn’t be used instead of other more “classical” Ada expressions… then its use is quite verbose).