[GAP] Question about subprogram syntax

Anthony S Ruocco aruocco at rwu.edu
Tue Feb 21 20:53:30 CET 2006


Maybe we are over-shooting the mark here as we are talking to students, not language aficionados.  I like to tout the power of Ada is in coding what you want to do. Instead of doing a lot of language oriented discussion why not back-step to how we actually use a function, that is

  Y = f(x)  

The function manipulates an input x to yield an output y.  Let f(x) be x+2 then

X	f(x)
1	3
2	5
Etc

If f(x) always returned the same value, then there would not be a function, but a constant.

Now in the code we would use

Y := f(x);  -- which looks a lot like the actual thing we want to do

In the event that f(x) always returned a constant then create a constant and use it

B    : constant int 45;

Y : = B;   --- which still looks a lot like what we want to do, and gives us flexibility in resetting B later.

Personally, I cant see the need for parameter-free subprograms.  Functions and procedures should manipulate something.  And if they are going to manipulate something, then we should control what they manipulate - hence use parameters and at least contain the blast zone.

Tony Ruocco


-----Original Message-----
From: Peter C. Chapin [mailto:pchapin at ecet.vtc.edu] 
Sent: Tuesday, February 21, 2006 10: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 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?

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. This 
might be useful, for example, when it becomes necessary to do some 
significant computation to obtain the desired value.

I don't know how often this actually comes up in the wild, though.

Peter



More information about the GAP mailing list