yakui
yakui copied to clipboard
Builder pattern
The recommended (cf examples) way to pass properties to widgets today is to do this:
let mut l = List::row();
l.main_axis_alignment = ...;
l.show_children(|| { ... });
I feel the temporary variable is not as ergonomic compared to the usual builder pattern:
List::row()
.main_axis_alignment(...)
.show_children(|| { ... });
The builder pattern is quite useful when one needs to migrate from short-hands i.e row(|| ..
to List::row().thing(..).show(|| )
as you can just edit the line and rustfmt will automatically re-separate it for you.
I do see a couple of issues with the builder pattern:
- Compile times (not sure)
- Auto-completion is weird as all fields of the builder are public (part of yakui's philosophy) so both the field and the builder function appear
- Leads to more indentation which is already a scarce resource
I'm guessing the last reason might be why it was chosen, but I might have missed something?