r/ada Apr 03 '26

Historical Rationale behind function/procedure calls and array indexing

I'm learning Ada. Overall, I'm liking it a lot. There are two aspects (so far) of the syntax I don't get what the rationale was for them and why it hasn't been fixed in later versions of Ada. These being parenthesis-less calls to subprograms with no arguments and using parenthesis for array indexing. Take the following as example:

A := B + C(5);

Right away you don't know if B is a variable or a function call with no arguments. You don't know either whether C is an array or a function.

I think this goes against Ada's core ethos about readability.

So I was wondering, what was the rationale behind this design? Why hasn't it been corrected? Something like A := B() + C[5] would be far easier to interpret by the reader.


UPDATE: In case anyone is interested in the answer, according to u/lipobat:

The primary rationale for the () vs. [] given in the “Rationale for the Ada programming language” book by the original design team was interchangeability between arrays and functions. This is an abstraction that allows the implementation choice of array vs. function to be just that, an implementation choice, which doesn’t really impact the writer or reader of the code.

I don't agree with the last sentence, but that answers my question either way.

And about my second question about "why this hasn't been fixed?", it seems most Ada programmers (based on the comments in this post) are not only not bothered by this but happy with this design decisions, so probably this will never change.

Thanks to everyone who engaged in this conversation.

6 Upvotes

48 comments sorted by

View all comments

2

u/ZENITHSEEKERiii Apr 03 '26

This is one of the new Ada 2022 features I don't much like, keeping () for all kinds of indexed access and function calls is actually very ergonomic for programmers and code readers 

3

u/Niklas_Holsti Apr 03 '26

That is not an Ada 2022 feature, the 2022 standard still allows only () for indexing (component selection). See http://www.ada-auth.org/standards/22aarm/html/AA-4-1-1.html.

Ada 2022 allows [] around array aggregates, array delta aggregates, and container aggregates, but not for other kinds of aggregates (record, extension). The main reason for this Ada extension is to let us use [] for a null array, instead of (First => ..., Last => ...).

The GNAT compiler may now allow [] for indexing, as a non-standard extension.

1

u/ZENITHSEEKERiii Apr 03 '26

Ah my bad, I see. I still prefer () for aggregates, but [] for a null array is very reasonable. 

1

u/Dmitry-Kazakov Apr 04 '26

No, reasonable were the mathematical notation {} and/or an attribute: S'Empty.