DIP 1030--Named Arguments--Community Review Round 1 Discussion

Adam D. Ruppe destructionator at gmail.com
Sun Feb 9 02:03:42 UTC 2020


On Sunday, 9 February 2020 at 01:47:35 UTC, Jon Degenhardt wrote:
> Now my question - I know function parameters names can be 
> retrieved by type introspection. What I don't know is the ways 
> those names can be used such that programs can break if a 
> parameter names change. Can you give some examples?

We can do named parameters in a library already, something like:

void func(int param) { }

int item;

callNamed!(func, param => item)(); // possible today. It pulls 
param name of func and from the given lambda to match up the item.


If func's param name were to change, that callNamed would fail, 
just like with this dip.

Of course since the syntax is weird and you need to import a 
lib... I never use this thing and I doubt anyone else does 
either. (I can't even find my implementation right now, though I 
know I have it somewhere).

I do use it extensively for runtime things though like generating 
command line parsers and web apis which can break, but that's 
expected on that interface anyway so of course I design for it.

But my policy on breakage though is I avoid it... unless I 
specifically mention in the documentation that you can't rely on 
it. Then if you do, that's your problem. So if I didn't want to 
do reliable names, I'd just do

/// $(WARNING the parameter names are NOT stable and may change 
without notice. )

and then there we go, disclaimer of liability :)


More information about the Digitalmars-d mailing list