Commenters debate API-stability risks of named parameters
4 Sep 21 10:09 PM · 2d ago · 4 comments · 1 source · development 4 of 5
Some argue making parameter names part of the public API would turn renaming into a breaking change, and suggest any such Rust feature should be explicit and opt-in for API designers rather than automatic.
“I would certainly not want any functions currently written suddenly be callable with named args because then all of a sudden changing an argument's name is a breaking change for crate authors.”
ekuberbotahamec Blog authorekuber Lobsters commenterschneems Lobsters commenter
The whole story postscomments the bright band is this development · numbered dots are the others · click one to jump
What people said 4 voices · verbatim
-
OCaml’s [labeled & optional arguments](https://ocaml.org/docs/labels) using `~` + `?` sigils is pretty novel in the functional space. I ended up liking it quite a lot ergonomically since a) you can easily forward along arguments, but also the labels can be alias for the scope meaning you don’t need to come up with argument names! A trivial…
-
THIS. (And Swift also does named/optional parameters well, IMO.) This has been one of my pain points in moving from Swift to Rust.
-
I like ObjC's solution: ``` example(named: 1, arg: 2) ``` desugars to something like: ``` example_named_arg(1, 2) ``` The arg order is fixed, but Rust's syntax error can suggest autofix. Lack of support for all the possible permutations is a plus: makes it harder to go wild with overly configurable methods. It doesn't need any new object types. It…
-
If Rust ever gets this I'd rather it used an anonymous struct as an argument instead. I would certainly not want any functions currently written suddenly be callable with named args because then all of a sudden changing an argument's name is a breaking change for crate authors. This would have to be explicit on the part of the API designer instead.
All 5 developments of Rust blog post on missing named/optional arguments sparks… →
Hacker NewsLobsters