preparing for named arguments
rjframe
dlang at ryanjframe.com
Tue Aug 27 02:09:55 UTC 2019
On Mon, 26 Aug 2019 22:19:38 +0000, aliak wrote:
>
> Should we maybe go through and make parameter names consistent where
> they obviously can be before named parameters gets to get in (should it
> get in)? e.g.:
>
> choose(condition: true, range1: a, range2: b)
> radial(range: a);
> take(range: a, n: 3);
> takeExactly(range: a, n: 3);
> takeOne(range: a);
I can't see any place where I'd use the parameter name for a range, so r/
range/r1/etc. wouldn't matter. My range variable name is the
documentation, or it's a literal array in a unittest. Based on what I've
read of others' code, that's typical; and range functions tend to be small
and named for what they do, so are self-documenting.
---
arr = myRange.sort!((a, b) => a > b)
.takeExactly(10) // .takeExactly(number: 10) doesn't aid readability,
.group // so why bother?
.assocArray;
---
Most of the time in other languages a named parameter will document a
literal argument or allow skipping parameters with default values. It
would be a good idea to skim Phobos to name-check, but I don't think it
will require a really large number of renames since most parameters
realistically won't be passed via their names.
--Ryan
More information about the Digitalmars-d
mailing list