News for hackers. Stuff that matters.
Re:Rust 1.64.0 by maxbond on Thursday September 22, 2022 @01:09PM (#32941761)
Why? The builder pattern is great.
Re:Rust 1.64.0 by kevincox on Thursday September 22, 2022 @01:32PM (#32942081)
It gets awkward really fast when you may need to set a value.

    let mut foo = build_foo()
        .with_a(8);

    if need_to_set_b {
        foo = foo.with_b(false);
    }

    let foo = foo.build();
Re:Rust 1.64.0 by maxbond on Thursday September 22, 2022 @01:44PM (#32942244)
Would look very similar with named arguments, no?
Re:Rust 1.64.0 by svieira on Thursday September 22, 2022 @02:44PM (#32942967)
Re:Rust 1.64.0 by kevincox on Thursday September 22, 2022 @01:51PM (#32942337)
Maybe. It depends a bit on how they are implemented. If there is a good way to pass "default" then you can just have a condition for that one argument. But if there is no way to pass "default" then it can get hairy.
Re:Rust 1.64.0 by maxbond on Thursday September 22, 2022 @04:15PM (#32944050)
For sure. I would like to see that in Rust as well, that would be nice. I am willing to put up with the lack of variadic & named arguments for the goodness the borrow checker brings me, but I can see how that would improve the ergonomics substantially.
Re:Rust 1.64.0 by joseluis on Thursday September 22, 2022 @01:22PM (#32941932)
Having both approaches available would be better IMHO. Builder pattern is very nice but I frequently miss having named arguments too. Even if macros can partially fullfill that need, it's not the same and introduces more quirks and complexity...
Re:Rust 1.64.0 by Ygg2 on Thursday September 22, 2022 @04:37PM (#32944307)
Problem with named parameters is that they make renaming function params a breaking change.
Re:Rust 1.64.0 by metaltyphoon on Friday September 23, 2022 @12:22AM (#32948030)
Unless the IDE doesn’t support this refactoring? It’s ridiculously easy in C# and VS or VSC.
Re:Rust 1.64.0 by setr on Friday September 23, 2022 @12:53AM (#32948205)
A (public) library doesn't have access to all codebases depending on it.
Re:Rust 1.64.0 by Ygg2 on Friday September 23, 2022 @05:26AM (#32949660)
Even there changing the method param will invalidate semver specification.
Re:Rust 1.64.0 by maxbond on Thursday September 22, 2022 @01:43PM (#32942225)
Fair enough.