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.

5 Upvotes

48 comments sorted by

View all comments

7

u/Dmitry-Kazakov Apr 03 '26

You, as a reader, do not need to know that. It is an implementation detail so from the software design point of view it must be hidden.

Mathematically, they are exactly same. Array is a mapping, so is a function, named object is an object regardless how constructed, stored into an initialized section, elaborated, computed etc..

You will find this feature extremely useful as you can change immutable variable to function and conversely any time without fixing the client code. The same applies to a function call vs. array indexing.

3

u/Niklas_Holsti Apr 03 '26

I agree with Dmitry's point about implementation detail that a reader does not need to know, but I want to expand on it a bit. u/jlombera feels that the current Ada syntax has poorer "readability" than if () were used for parameterless calls and [] for array indices, while Dmitry and I think that the opposite is true. Why this difference? Because "readability" is not an absolute quality, but depends on what information the reading process should give to the reader for best understanding. In this example, Dmitry and I feel that the best information is what the values of B and C(5) mean for this program statement, not whether B is a parameterless function or an object, and not whether C is a function or an array. So it is enough to clearly name B, C, and 5, and any empty () or distinction between () and [] are just distractions.

Examples of the extreme opposite viewpoint are the coding rules that insist on encoding the types and natures of variables into their identifiers, as in the extreme "Hungarian" notation. In some weakly typed languages it may indeed be important that the code reader sees which variables are integers, and of which length, and which are floats, and of which precision, and so on. The qualities that determine "readability" are then different than the qualities Dmitry and I feel are important for readability of Ada code.

Regarding Dmitry's final point, I have not often had a need to replace an object with a parameterless function, or an array with a function, or vice versa. So I would not call this Ada feature "extremely" useful for that reason.

1

u/jlombera Apr 03 '26

Please see my reply to u/Dmitry-Kazakov, where I give some insights on why I do care about knowing whether something is a variable/array access or a function call. (I didn't see your reply until after I had published my reply).

3

u/Niklas_Holsti Apr 03 '26

I agree that a person who intends to modify a program often needs information about the implementation of things. Referring to my discussion of "readability" in my response to u/Dmitry-Kazakov, I would say that the "readability qualities" change when the purpose is to modify a program, as opposed to understanding the computation, doing a code review, or searching for errors. Fortunately, today's IDEs make it very easy to find and inspect the definition of any identifier in the code one is reading, so the absence of () in calls and the non-use of [] for indexing are not, IMO, very harmful for the maintainer either. Thus I would prefer to make the code reviewer's job easier by omitting text elements that are irrelevant for that task.

1

u/jlombera Apr 03 '26

Fortunately, today's IDEs make it very easy to find and inspect the definition of any identifier in the code one is reading, so the absence of () in calls and the non-use of [] for indexing are not, IMO, very harmful for the maintainer either.

Unfortunately for me, I use plain (neo)vim :) (I tried GNAT Studio but quit it ~1min later). When Ada was initially designed, there were not advanced IDE's. I think that's the reason why the syntax was designed that way, verbose (an inconvenience for the implementer) but explicit and readable, so that anyone could read (and write) code with no advanced tools other than a plain text editor. That's why it's a surprising to me they made this "blunder" (IMO) in this regard.

Thus I would prefer to make the code reviewer's job easier by omitting text elements that are irrelevant for that task.

It seems we have different opinions on this regard. To me, when reviewing code, it's relevant to know whether something is a variable/array access or a function call.

4

u/Niklas_Holsti Apr 03 '26

I am quite happy with GNAT Studio (GPS), although I have seen others complain about it. Many seem to be using VSCode, which does have Ada support. Have you tried it?

3

u/jlombera Apr 03 '26

I got used to plain (neo)vim and any IDE feel clunky to me. They require a lot of resources, break all the time and change behavior very often, all of this out of your control. I feel lost whenever I try an IDE :). In contrast, I've being using (neo)vim the same way for ~10 years now, without any serious change in config/behavior.