I use Ada for my personal projects, largely out of admiration for the language, but I’m entirely self-taught in Ada, and the literature on its usage is… well, somewhat scant in comparison to, say, C++.
Not every language is perfect, but some things in the standard Ada library seem far too cumbersome. So much so, that I have to wonder if I’m doing things right. I’ve looked at the ARM, perhaps not well, and rosetta code is down at the moment, so I thought I’d inquire here.
Queues
Setting up a queue seems to involve way more effort than it should:
- You have to include two separate packages:
Containers.Synchronized_Queue_Interfaces
-
Containers.Unbounded_Synchronized_Queues
or one of the other three variants
- You have to
use all type Ada.Containers.Count_Type
if you want to check whether it’s empty.
The payoff? For all the effort you put into creating it, the resulting queue offers less functionality than other languages’. All you can do is Enqueue
, Dequeue
, and check usage. You can’t iterate through the queue to see what’s there and possibly modify it, nor search through it, let alone split the queue. There isn’t even an .Is_Empty
method to tell you when it’s exhausted.
Queues are pretty common, and I’ve never seen one so bare bones. Is there something more functional than this in the standard library? If not, do people recommend a different library (e.g,. the Simple Components library) or do you typically roll your own?
(I realize there may be good reasons for the library to do things this way; I’m just wondering what people do about it.)
Iteration through maps
Suppose I set up a map M
and want to iterate through it.
-
for E of M
iterates through the map’s elements, not through its keys. I wish they had returned the keys instead, since often that’s what I want, and it’s easy to obtain the elements from the keys, and not so much the converse. But this does make sense.
-
for C in M.Iterate
iterates a cursor through the key/pair combinations. This makes sense, too. But…
- Using
Cursor
is, again, cumbersome. As far as I can tell, I can’t do this: C.Key
or C.Element
. Instead, I have to with all type Map_Type.Cursor
to get Key(C)
and Element(C)
, or else qualify the functions fully: Map_Type.Key(C)
or Map_Type.Element(C)
.
(I think Ada 2022 introduces functionality to let me treat a cursor the way I want, but if so, I have to update my gnat: version 20210519-103.)
So what am I doing wrong?
Have I missed something, or is this indeed the standard way of doing these things in Ada? I would be grateful for any direction, because I don’t use Ada often enough to remember these two things, and the compiler’s help error messages are not the greatest.
Honestly!
I apologize if it comes across as a complaint. I realize there’s no perfect language, and just want to know if I’m missing something, because Ada does so many things right. I can make much, much longer lists of my complaints with C++, and a somewhat longer list of complaints with Rust, than I can with Ada.
9 posts - 4 participants
Read full topic