yakui icon indicating copy to clipboard operation
yakui copied to clipboard

Builder pattern

Open Uriopass opened this issue 6 months ago • 4 comments

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?

Uriopass avatar Dec 23 '23 21:12 Uriopass