[GAP] Question about subprogram syntax

Robert Dewar dewar at adacore.com
Tue Feb 21 17:03:38 CET 2006


Diego Alonso Cáceres wrote:
> Hello everyone,
> 
> I've been teaching Ada for three years now and often my students make me
> the same question:
> "Why don't parameter-less subprograms have empty brackets like C or Java? 
> The code would be easier to read and maintain. It would be also possible to 
> have a variable and a procedure with the same name."

Well to start, we definitely do NOT want to allow overloading of this
kind. I can't see any case in which this would make code easier to read.
There is an argument for subprogram overloading, but not for variable
overloading.

As for readability, it is a matter of opinion whether this would make
things easier to read. If you are very used to Java or C, you may find
it more readable. Personally I find it to be annoying junk, and that
was the majority feeling among those defining Ada.
> 
> I really don't what to answer because I think the same. Wasn't Ada thought 
> as "write once, read many times" or "Ada enhances readability"? Why inherit
> this from Pascal?

Because we thought it was more readable than the empty parens.
> 
> Have you think about changing it (suppossing using always brackets was a 
> good idea)? I  know the change would make old Ada'95 and Ada'83 code 
> incompatible and that Ada 200X is going to be an Amendment rather than a 
> Revision, but still ...

I don't think that anyone would agree that using parens was or is
a good idea within the Ada community. The idea of making it an
incompatible change is completely out of the question.

This matter was discussed extensively 25 years ago, but I don't know
if it is possible to track down these discussions. As I remember there
was some sentiment for empty parens, but it was definitely in the
minority. The readability view is that parens are there to enclose
something, and enclosing nothing makes little sense.

Certainly I would find the following code horrible

     Initiate_Program ();
     Perform_Computations ();
     Terminate_Execution ();

I fail to see any value at all in the empty parens, C style, here.

As for functions, if I write

     X : List := Empty_List;

I think that's quite fine. In fact from the programmers point of
view, it's not really important whether Empty_List is a constant
or a function returning a value, so it seems right to have the
same syntax.



More information about the GAP mailing list