Henry Miller
2018-08-16 17:44:58 UTC
In the past couple months I've seen several proposals for names parameters. Each with a list of pros and cons, and because there are cons arguments against them. I think we need a discussion on what we want assuming some strawman acceptable syntax, and some thought of how many limitations in corner cases we are willing to accept.
I can think of 4 uses for names parameters. (If you don't understand these I have simple code examples)
1 . a function with more than one parameter of the same type is called with the parameters in the wrong order
* Some people want this to be a compilation error, some want the compiler to correct the problem and continue
2. a function wants to take the same type to mean different things in different contexts
3. it isn't obvious from the type alone what a parameter means
4. A function has a bunch of defaulted arguments and you want to change one of the latter ones without specifying all the others
First question: is this complete?
Second, which problems are worth solving?
Third, for problems worth solving, which is the better solution, and how strongly attached to it are you?
For the first the motivating code is something like:
class myMatrix {
T GetCell(int row, int column);
...
};
in code:
cell = matrix.GetCell(column, row);
This will compile just fine in C++17, but the code is undoubtedly wrong. In C++2n do you want this to be a compiler error, or correct code?
Second:
class point {
point(double x, double y);
point(double distance, double angle);
...
};
This code does not compile in C++17. Do we want to make this case work?
Third:
class myString {
int compare(myString, bool CaseSensitive);
...
};
in code
if(str.compare(otherString, false) == 0) ... // what does this mean, why would you call compare and not compare?
This code is legal C++17, but it is user hostile. False in the context of reading the function makes no intuitive sense. Qt has created an enum for this, but it can be argued that this is too heavy. (you may or may not agree with the argument)
Fourth:
// warning, marketing regularly changes the default value of this function
void foo(double a = 1234.5, int b = 6789);
foo(b:=1234);
This won't compile in C++17. However it seems like it would be useful to not clutter function calls with default parameters that you don't care about. In the case I gave it is a maintenance problem to update all uses of foo every time the defaults change, though I'm not sure if this is actually a common problem.
I can think of 4 uses for names parameters. (If you don't understand these I have simple code examples)
1 . a function with more than one parameter of the same type is called with the parameters in the wrong order
* Some people want this to be a compilation error, some want the compiler to correct the problem and continue
2. a function wants to take the same type to mean different things in different contexts
3. it isn't obvious from the type alone what a parameter means
4. A function has a bunch of defaulted arguments and you want to change one of the latter ones without specifying all the others
First question: is this complete?
Second, which problems are worth solving?
Third, for problems worth solving, which is the better solution, and how strongly attached to it are you?
For the first the motivating code is something like:
class myMatrix {
T GetCell(int row, int column);
...
};
in code:
cell = matrix.GetCell(column, row);
This will compile just fine in C++17, but the code is undoubtedly wrong. In C++2n do you want this to be a compiler error, or correct code?
Second:
class point {
point(double x, double y);
point(double distance, double angle);
...
};
This code does not compile in C++17. Do we want to make this case work?
Third:
class myString {
int compare(myString, bool CaseSensitive);
...
};
in code
if(str.compare(otherString, false) == 0) ... // what does this mean, why would you call compare and not compare?
This code is legal C++17, but it is user hostile. False in the context of reading the function makes no intuitive sense. Qt has created an enum for this, but it can be argued that this is too heavy. (you may or may not agree with the argument)
Fourth:
// warning, marketing regularly changes the default value of this function
void foo(double a = 1234.5, int b = 6789);
foo(b:=1234);
This won't compile in C++17. However it seems like it would be useful to not clutter function calls with default parameters that you don't care about. In the case I gave it is a maintenance problem to update all uses of foo every time the defaults change, though I'm not sure if this is actually a common problem.
--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1534441498.3721109.1476442920.71D445BF%40webmail.messagingengine.com.
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+***@isocpp.org.
To post to this group, send email to std-***@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/1534441498.3721109.1476442920.71D445BF%40webmail.messagingengine.com.