IMO, it's not about named parameters;
furthermore, it is not about readability, but this IMO
is a maintenance issue.
Think about a procedure that has two parameters and a lot of callers
and you want to add a third one.
it would be nice if you could specify a default value for the new
third parameter and don't have to change all the callers that use
only two.
So IMO a sensible extension to the Pascal syntax could be:
if there is a initialization on the procedure declaration, the parameter
is optional.
Example:
procecure P (x : integer; y : boolean; c: char := ' ');
the first two parameters are mandatory, the third is optional.
Calls to P with 2 and 3 parameters are both valid.
Another extension would be:
specify the formal parameter's name on call, that is:
P (y := true, c := '*', x := 25);
which allows for a different sequence of arguments on the procedure call
but this is a different topic and should be discussed seperate from the
default issue.
I guess, that all this will be limited to byvalue parameters ... not for
var parameters ...
Kind regards
Bernd
Am 27.05.2017 um 08:17 schrieb Mr Bee via fpc-pascal:
Hi,
As Pascal mostly well known as a safe, easy to read, and elegant
language, don't you think Pascal needs named parameter? I mean for ALL
kind of parameters, not just for Variants. When you have a function
with many parameters having default values, you know that named
parameter is desirable. For example:
function f(p1: string = ''; p2: integer = 0; p3: boolean = false);
But you only need to supply the third parameter, you still must supply
the first and second ones with appropriate default values, like this:
f('', 0, true);
while with named parameter, you can do this:
f(p3 := true);
I believe it would raise Pascal's code readability. I know it has been
discussed before. I know somehow the parser had been able to read such
syntax. So, why don't we have the option to enable it for people who
want it? Kinda a syntax switch mode.
What do you think? :)
--
Regards,
–Mr Bee
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal