Re:A simple UI framework for Rust
by escherize on Tuesday May 19, 2015 @10:52AM
(#9570448)
The macro is a better solution, since you can't rely on every library doing this kind of thing.
[ Parent
| on HN ]
Why wouldn't I want to do
dialog.set_title("blah");
dialog.set_size_piels(100, 100);
on two lines?
Different strokes. It's a common idiom in JavaScript, for instance. You can do multiple lines if you want, nothing stops you.
Re:A simple UI framework for Rust
by tedunangst on Tuesday May 19, 2015 @11:03AM
(#9570560)
Because functional programming.
To 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.
I 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.