function argument 'shorthand'
Bill_member at pathlink.com
Wed May 24 22:26:00 PDT 2006
In article <e4tv46$2007$1 at digitaldaemon.com>, Dave says...
>Walter Bright wrote:
>> Dave wrote:
>>> Couldn't find this in the archive, so I don't know if it's been discussed
>>> One of the things I like about Pascal is that you can specify function
>>> of the same type w/o repeating the type. So, in D we could:
>>> int foo(int x, y, z) // y and z are type int
>>> int bar(int x = 1, y = 2, z = 3) // y and z are type int
>>> void baz(int x, y, double d, f = 3.14159) // y is an int, f is a double
>> It has grammatical ambiguities. Consider:
>> int foo(int x, y);
>> Is the second a declaration of y of type int, or is it a parameter of
>> type y?
>(Red faced) Of course.
So what about a semi colon or colon or something instead of the comma?
int foo(int x ; y, float z);
int foo(int x : y : z);
Course, then the syntax doesn't resemble the declaration syntax any more.
Personally, I think arguments with types but not names is bad style anyway. The
argument name gives you a clue as to what that parameter is supposed to be for.
If you see
there's no way to tell what those ints are for, and you can't document them
either because there's no parameter name to refer to in the documentation.
More information about the Digitalmars-d