Critics highlight practical verbosity costs of struct approach
5 Yesterday 6:50 PM · 16h ago · 8 comments · 1 source · development 5 of 6
Commenters push back on the essay's claim that struct-based parameters are reasonable, showing that the boilerplate—defining structs, implementing Default, using spread syntax—is significantly more verbose than simple named parameter syntax. One commenter questions whether the approach is actually good code.
“This is supposed to be good code?? I don't see how people can look at struct constructors and think…”
spillybonesitamarst Rust developer / authorSteve Klabnik Rust contributor (referenced)ekuber Rust team member
The whole story postscomments the bright band is this development · numbered dots are the others · click one to jump
What people said 8 voices · verbatim
-
OP says instead of this, ``` request(url, follow_redirects: false); ``` all you have to do is this: ``` struct RequestOptions { timeout: Duration, follow_redirects: bool, } impl Default for RequestOptions { fn default() -> Self { Self { timeout: Duration::from_secs(30), follow_redirects: true, } } } request( url, RequestOptions { follow_redirects…
-
A lot of cope. Reads like the sort of article the Go community would write... Speaking as someone that loves Go. The point of optional arguments is that a predetermined default value is used if nothing is passed, passing `none` is not the same as passing nothing since none is a value in languages like Rust and Python. Using structs for keyword…
-
I don't see the difference with the RFC feature. The fact that yours doesn't `derive(Default)`? I don't _think_ that's required for `default_field_values` either (but the examples make it ambiguous).
-
Yeah, I think their point about friction when writing making you think less applies more to the code in their AI generated article than to single function calls.
-
Lots of things don't work with `impl Trait` arguments. `arg as _`, `arg.into()`, sometimes even `&arg` when you get `&T` instead of `T`'s `Deref` or `&dyn`
-
Oh. Okay. Thanks for pointing that out. I guess I thought the Default derive was required.
-
In ObjC they are literally part of the function name. let foo_ref = foo:a;
-
That's not going to work with `impl Trait` arguments ?
All 6 developments of Rust dev argues structs beat named arguments for API design →
LobstersHacker News