5 ms·
Okay, yes, you could do that, but the library itself provides this as its idiomatic way of doing things.
by rylee 11y ago
Okay, yes, you could do that, but the library itself provides this as its idiomatic way of doing things.
- escherize 11y agoThe macro is a better solution, since you can't rely on every library doing this kind of thing.
- skj 11y agoWhy wouldn't I want to do dialog.set_title("blah"); dialog.set_size_piels(100, 100); on two lines?
- tedunangst 11y agoBecause functional programming.
- sp332 11y agoTo expand a bit: Sometimes, instead of thinking about nouns all the time, you want to think about verbs. Instead of saying "mutate this noun by applying verb1" and then "mutate this noun by applying verb2" etc, you are creating a new verb. The new verb is "verb1 then verb2 then...." And then when you have the verb defined, you apply it to your object.
- Jweb_Guru 11y agoI feel APIs like that are a bit misleading in Rust in many cases, though, since they're also mutating the original. In Rust, if you want to perform a functional update like that you should take the type by move, but almost everyone just uses mutating APIs because mutation is explicit in the signature anyway. I think that's one of the biggest differences in practice between Rust and other MLs (with which it otherwise has a lot in common): in most MLs, mutation is treated as a last resort, while in Rust it's extremely common because it (generally) doesn't have nonlocal effects.
- kedean 11y agoDifferent strokes. It's a common idiom in JavaScript, for instance. You can do multiple lines if you want, nothing stops you.