DIP 1019--Named Arguments Lite--Community Review Round 2
Exil
Exil at gmall.com
Wed Jun 5 15:25:52 UTC 2019
> Named arguments proposed by this DIP have no effect on the
> ordering of arguments in function calls.
I feel like this needs to be expanded. Does it mean that using
named parameters the parameters still need to follow the same
order?
> Named arguments proposed by this DIP do not allow default
> parameters to be skipped..
Please expand this sentence. Why isn't this being
proposed/implemented? This is extremely useful.
void fun(int a = 0, int lot = 1, int of = 2, int parameters =
4, int foo = 5);
fun( foo: 10 );
fun( 0, 1, 2, 4, foo: 10 ); // need to repeat parameters
needlessly
> If a function is defined with some of its parameter names
> omitted, arguments to those parameters can labeled with an
> empty name.
>
> void fun(int);
>
> fun(:10);
Why is this included, what is the use case for it? Why wouldn't
you just use fun(10) instead? If ordering is required why require
the ":" at all?
I also don't see anywhere that this wouldn't be allowed?
void fun( int a, int b );
fun( a: 0, 10 );
The description shows this:
void drawRect(int x, int y, int width, int height);
drawRect(x: 0, y: 0, width: 1, height: 1);
drawRect(0, 0, width: 1, height: 1); // Also valid
But there is nothing in the DIP that states that this is valid or
what rules it needs to follow? Like above with the named
parameter appearing before arguments or inbetween.
> Overridden member functions can be called with a set of names
> matching any of the function definitions which are visible
> through the object used to call those functions.
>
> class A {
> int a(int x);
> }
>
> class B : A {
> override int a(int z);
> }
>
> auto b = new B;
> A a = cast(A)b;
>
> b.a(z: 1); // valid
> b.a(x: 1); // valid
> a.a(x: 1); // valid
> a.a(z: 1); // error
Which functions do these call? Does b.a(x: 1) call B.a() or
A.a()? You can call A.a() specifically, this needs to be
clarified as to which is called.
https://run.dlang.io/is/eQ7X4p
import std.stdio;
class A {
void a(int x) { writeln("A"); }
}
class B : A {
override void a(int z) { writeln("B"); }
}
void main() {
auto b = new B;
b.A.a( 10 );
b.a( 10 );
}
More information about the Digitalmars-d
mailing list