The problem with structured types as params (records or objects) is that is needed anyway at some point to set each value (in worst case), and if you have a method that sets them all, if you add a new param/field, all you hvae to do is adjust the method that sets them all, and fix all his calls, and you are sure all params are set otherwise it won't compile at all. So the problem is translated to that method.
Yes, but the record representing the parameters can in principle at least be initialised from a constant:
const
descriptionTemplate: TPortDescription= (
baseName: 'ttyUSB';
idVendor: '';
idProduct: '';
busType: '';
driverName: 'usb-serial/drivers/ftdi_sio';
manufacturer: ''; (* Avoid: varies on counterfeits etc. *)
product: 'FT232R USB UART';
serial: 'A50285BI' (* Common in counterfeit R/O EEPROM *)
);
var
description: TPortDescription= descriptionTemplate;
...
result := FindPortByDescription(description, portScan)
As long as the receiving function is not receiving it as a var parameter, then the intermediate variable can be skipped, and just the constant used.
Somewhat disconnected, but does meet than named parameter requirement.
...thinking things through, once (named) parameters are encapsulated in a record the overloading is actually much less stressed: it's either that record type, or it's not.
Agreed. This solves the overloading issues.
And this already works, no changes required.
Of course to initialize with something other an constant, a variable is needed.
{$mode objfpc}
{$H+}
program namedparam;
type TRec1 = record
a: integer;
b: string;
end;
procedure np(constref rec1: TRec1);
begin
writeln('a: ', rec1.a, ' b: ', rec1.b);
end;
const
p0 : TRec1 = (a: 5; b: 'b');
var
p1 : TRec1; // = p0; namedparam.pas(19,3) Fatal: Syntax error, "(" expected but "identifier P0" found
begin
np(p0);
p1.a := 7;
p1.b := 'second';
np(p1);
end.
$ fpc namedparam.pas
Free Pascal Compiler version 3.2.2 [2022/08/17] for x86_64
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling namedparam.pas
Linking namedparam
26 lines compiled, 0.1 sec
$ ./namedparam
a: 5 b: b
a: 7 b: second