Hi David,
> Date: 2026-11-27 13:57:10+0100
> From: David Brown <david.brown@hesbynett.no>
>
[...]
> > Hmmm, yeah, so two people here have expressed preference for 'default'.
> > When implementing this with macros in C, I also tried first to use the
> > 'default' keyword, but I couldn't find a way to do it.
>
> I would certainly greatly prefer having "default" rather than omitting the
> argument entirely
Thanks!
> - though I am still not convinced that default values in
> arbitrary positions is a good idea. (I'd rather see progress made towards
> name arguments in calls, as supported in many other languages - if that ever
> makes it to C++, then this whole idea is moot.)
I dislike named parameters. They make the call too long, and don't give
much benefit.
They give tremendous readability and clarity benefit, and alleviate problems with multi-argument functions.
In C++, the best you can do right now is approximate named function arguments by using designated initialization with a struct. This is more limited than named arguments would be, and mildly tedious on the author side, but the fact that people do it anyway - and many people are happy to learn this idiom - is a pretty clear indicator of the value of using names.
'default' better expresses the intent: this parameter has a default
value.
This might be literally true but practically speaking is definitely false.
Yes, in some sense, it expresses the intent that sort(r, default, f) is using the default value of the 2nd parameter. However, this does absolutely nothing to express the actual intent of the code, because you have to actually know the order of all the parameters, which is usually not relevant to either the caller or the reader. This also scales terribly when the one argument you want to specify is the 6th one. Or was it the 7th? Or 5th? It also doesn't hold up very well on refactoring.
On the other hand, sort(r, by: f) (or whatever syntax) actually does express the intent, very clearly, in a way that works great regardless of which argument(s) you actually want to specify. You don't even need to know what order we go in.
The explicit default is at least better than sort(r,,f), which has the same counting and lack-of-intent-or-clarity problem but is additionally indistinguishable from a typo. But it's really not a good solution to the problem.
Barry