Interesting, though this could lead to a lot of repetition in function declarations when you have the same public name as internal name.
Could you explain your concerns?
Creating a struct for the majority of functions just to be able to name your parameters is a lot of boilerplate as you can see in your own example. Named arguments are more ergonomic and probably a lot easier to get for beginners.
It is not exactly the same thing. It's another tool that you can use for specific situations. I'm not saying named arguments are the solution for every situation, builder patterns, struct arguments, etc. should still be used when more practical. But like there exists multiple loop constructs (+ iterators) there can be multiple tools to make APIs more ergonomic.
Because default arguments spawn a lot of additional discussion on technical problems, debate on best practices, etc. etc. Those discussions are not all relevant to named arguments and this proposal is a way to get things moving in the right a direction.
Of course, I mentioned in the proposal that we should think ahead to limit the restrictions we set for the possible future addition of default arguments.
I would not want my argument names to be part of the API by default. Renaming an argument would then automatically require a major version bump. This means you have to carefully think about the best possible argument names in addition to the function name when you introduce it. And for me, personally, my argument names tend to be relatively mediocre until I find better names along the way.
As for the repetition, I agree that having pub
, pub
, pub
repeated multiple times in the function declaration is not exactly pretty. But only giving a binary choice of either no arguments are named or all arguments are named seems a bit limiting.
Obviously not all arguments need to be named. Take the example I gave with
http.get("https://www.rust-lang.org/en-US/", timeout: None);
It's pretty obvious that you want to pass a url as first argument. But having a trailing None
could mean pretty much anything. Creating a struct just to be able to name that one argument is IMHO pretty silly.