[GAP] Question about subprogram syntax

Riehle, Richard (CIV) rdriehle at nps.edu
Wed Feb 22 02:01:39 CET 2006



-----Original Message-----
From: gap-bounces at gnat.info [mailto:gap-bounces at gnat.info] On Behalf Of Peter C. Chapin
Sent: Tuesday, February 21, 2006 7:37 AM
To: GNAT Academic Program discussion list
Subject: Re: [GAP] Question about subprogram syntax


On Tue, 21 Feb 2006, Diego Alonso Cáceres wrote:

> 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."

I'm not an expert but my understanding was that this is considered a 
feature. The idea is that it is possible to replace a constant with a 
parameterless function without editing any code that uses that constant.

 	A := B;

B might be a value today, but a parameterless function tomorrow. 

==================================================================

You have just touched on an important principle, "referential
transparency."   We usually see this principle in functional
languages rather than imperative languages.   Eiffel's designer
tried to make this a part of the Eiffel language.   

In my earlier example, the one where I use a function for a
constant instead of a global constant, is based on this
principle.   Enumerated types, as paramterless functions work
off this principle.   The overloading of parentheses instead of
square brackets for arrays also reflects this principle.  

As with any such principle, there are trade-offs.   However, there
is never a substantive ambiguity in Ada.   I once had a conversation
with Jean Ichbiah about this issue.  After he finished explaining it
to me (I was a doubter myself for a while), I realize what he was
trying to accomplish and the rationale for it.  Reasonable people can
still disagree about it, but I have never known it to create a serious
problem for anyone.

The C model is a problem since one must always include the parentheses,
or use square brackets.   In this model, referential transparency is 
never available.   The client of a contract needs to know more about
the contract than should be required.

Richard Riehle




More information about the GAP mailing list