Entomy / Ada-Improvements

Repository of Ada language improvement ideas
GNU General Public License v3.0
4 stars 0 forks source link

Subroutine simplification #6

Open Entomy opened 5 years ago

Entomy commented 5 years ago

Ada does:

function Example_Function(… parameters …) return Value;

procedure Example_Procedure(… parameters …);

It should be:

function Example(… parameters …) return Value;

function Example(… parameters …);

Rationale: A return value is essentially just another parameter, so let's treat it more like that. Most languages don't really make the distinction, and depending on the syntax may use a void to say it doesn't really return anything.

I should also explain that in Ada the two are not simply a distinction between whether there was a return type or not, and are semantically distinct. Functions can be designated pure while procedures can not. If keeping comparability with older Ada standards, procedures can have out parameters while functions can not. The two should be compatible, only differing in return type, and making them the same construct accomplishes that in the most sensible way.

This also conveniently simplifies parsing since subroutine definitions can be determined with one definition type, with a simple check inside for whether a return clause is found.