Discussion Thread: DIP 1030--Named Arguments--Final Review

Luhrel lucien.perregaux at gmail.com
Fri May 22 19:16:25 UTC 2020


On Wednesday, 13 May 2020 at 13:56:26 UTC, Steven Schveighoffer 
wrote:
> Hm... an interesting proposition, we could provide a way to 
> disallow using names if the name starts with something like _:
>
> void foo(int _x)
> {
>    alias x = _x;
>    ...
> }
>
> foo(_x: 1); // Error
> foo(1); // OK
>
> It might be better than having to use .di files to prevent 
> parameter-name based calling.
>
> -Steve

What about a @required (or a better name) that will force the 
user to use the named argument ?

---
void copy(string src, @required string dest) {}

copy(source: "myfile", "yourfile"); // Error: Missing named 
argument `dest:` before `"yourfile"`
copy("myfile", dest: "yourfile"); // Ok
---

Also, should named args, if used, always be spelt correctly ?
---
void anotherCopy(string src, @required destination: string dst) {}

void anotherCopy("file1", dest: "file2"): // Error: Named 
argument `dest:` must be spelt `destination:`
void anotherCopy("file1", destination: "file2"); // Ok
---



More information about the Digitalmars-d mailing list