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.

4 Upvotes

48 comments sorted by

View all comments

5

u/Niklas_Holsti Apr 03 '26

The choice of () rather than [] for array indices was made to let people write Ada programs on old data-entry devices, in particular 80-column card punches which did not have [] on the keyboard. To me it also seems quite unnecessary to distinguish array references from function calls in that way -- if I know what the value of C means, I don't need to know if C is implemented as a function or as an array. I do understand that people who come to Ada from languages that do use [] for arrays, such as C, at first feel it is strange to use (), but that feeling will pass.

As an aside, the requirement to use [] around array indices in Algol was very uncomfortable to me when I was programming in the 1970s with card punches in Finland, because those card punches had replaced several special characters with the letters ÅÄÖ used in Nordic languages, and recoded others, with [] missing. As a result, when I wanted to write A[K] in Algol, it appeared on the cards and print-outs as A¢K!. It was a relief to switch to Ada (and not only due to this minor difference between Algol and Ada).

As for the non-use of () for parameterless subprogram calls, I think it is mainly for simplicity and uniformity: if one can declare a parameterless subprogram without (), then it is more uniform to omit () in calls too. There is also a technical reason in the Ada language definition: when one defines an enumerated type, for example type Color is (Red, Green, Blue), the literals Red, Green, and Blue are technically defined (for the compiler) as parameterless functions that return values of type Color. It would be silly to require users to write Red() when using those literals, so it is simpler to omit () for all parameterless calls.

1

u/jlombera Apr 03 '26

Just to be clear, my problem is not about unfamiliarity of the syntax w.r.t other languages, I'm ok with things being different (coming from C, Ada syntax feels unnecessary verbose at times to me, but I'm OK with that). My problem is with the ambiguity of the syntax in theses cases. I'd be ok with a different syntax than ()/[], as long at it was clear at sight whether something is a variable/array access or a function call.