I hate this idea. It just clutters the UI too much and adds noise especially if it's a UI you're familiar with. The C/C++ language is noisy enough without all this. Modern IDEs alleviate the need to be reminded inline what the values are for. On top of the fact, just about every IDE invented in the last 10 years offers code completion making this useless IMHO.
On the contrary, I would say that it cleans things up amazingly. As the language currently is, if I want to change one of the default values, I need to specify every single value up to that point. func(5,0,0,NULL,0,true,true,false,NULL,true); func(verbose: true); With named parameters, I can just specify the differences between my function call and the default values.
A proposal for named arguments for C++
21–30 of 62 posts
Re: A proposal for named arguments for C++
#22I like this idea in theory. the rectangle the example is a good one that I've personally tripped over before. That being said, this could hurt readability in some cases as single lines of code are going to get larger, especially with length parameter names. Another issue I forsee is a code style where parameters are prefixed with p_. Having to type that prefix each time would be annoying, but finding a readable synta…
int myfunc(float x, y, z, r, g, b, a);
instead of int myfunc(float x, float y, float z, float r, float g, float b, float a);
Yes, I know about structs, but often that's not applicable. And if the type name is some long thing, then you have to really look carefully to notice they are all the same type. It seems this style is now being seen as a feature, although I don't know of any language that required repeating the type for each parameter until C and C++ adopted this for the new style function prototype declarations. I was very sorry to see that D has also adopted this "feature". I believe go allows multiple declarations of the same type. I'd much rather see this fixed in C and C++ than have them clutter up things with named parameters.Re: A proposal for named arguments for C++
#23What's the argument against, well, named arguments? Is it a matter of brevity versus verbosity?
Well, function specifications in the link table would have to become more verbose, and the linker would have additional decisions to make. You could also wind up deferring a lot of problems that could be caught by compile-time checking until link-time, which might also be run-time. The problem that they're trying to solve is that people often use 5 arguments when a single struct would do.
Re: A proposal for named arguments for C++
#24Earlier quoted context omitted.
It's not really the responsibility of the standard committee, right? C also has no standard ABI.
C absolutely has an ABI – you do not need a C compiler to call a C library.
Stdcall convention in C also often does some name mangling (leading underscore, trailing @ and the number of bytes on stack) but not always.
Also a C++ ABI would need to extend beyond simple calling conventions and also specify fixed behaviour of vtables, which i think compiler authors might balk at.
Re: A proposal for named arguments for C++
#25Re: A proposal for named arguments for C++
#26Earlier quoted context omitted.
It's not really the responsibility of the standard committee, right? C also has no standard ABI.
C absolutely has an ABI – you do not need a C compiler to call a C library.
Or am I misusing terminology?
Re: A proposal for named arguments for C++
#27One of my favorite C preprocessor hacks - emulating named parameters in C. https://gist.github.com/robmccoll/5236408528c8c664c201
Re: A proposal for named arguments for C++
#28Earlier quoted context omitted.
It's not really the responsibility of the standard committee, right? C also has no standard ABI.
C absolutely has an ABI – you do not need a C compiler to call a C library.
The problem with C++ ABIs is that C++ APIs tend to include much more substantial details in their headers. If you want to call a template or inline function, then you need a C++ compiler. Fundamentally, though, this is not any different from C macros -- a macro-heavy C API is going to require a C compiler to use.
Re: A proposal for named arguments for C++
#29Earlier quoted context omitted.
Well, function specifications in the link table would have to become more verbose, and the linker would have additional decisions to make. You could also wind up deferring a lot of problems that could be caught by compile-time checking until link-time, which might also be run-time. The problem that they're trying to solve is that people often use 5 arguments when a single struct would do.
No, this proposal does not affect the linker at all. Argument names would be resolved to positional arguments during compilation.
> In this proposal, the association of parameter names with a function for the purpose of making calls with named arguments to that function happens locally in each translation unit, and new declarations within a translation unit can change a function's ability to be called with named arguments at call sites below the new declaration (by using different names than a previous declaration).
Re: A proposal for named arguments for C++
#30One of my favorite C preprocessor hacks - emulating named parameters in C. https://gist.github.com/robmccoll/5236408528c8c664c201
If only named member initializers were supported in C++. Here's a similar hack that works in C++11, though it unfortunately requires declaring a global variable for each name (which I make less-bad by prefixing them with $, which is non-standard but supported by all major compilers): https://gist.github.com/kentonv/7553792