Quick poll: Which of these declarative UI trees looks the most legible to you?

235 views
Skip to first unread message

atd...@gmail.com

unread,
Jun 6, 2022, 8:52:54 PM6/6/22
to golang-nuts
Hi,

So I have a working implementation of a UI framework underway.
I've ended up providing ways to define the UI tree in a declarative way.


But to make sure it is legible, I have a gist with 3 examples of how the UI tree could be defined. (taken from an implementation of TODOMVC)

1. Full declarative structure specification but CSS classes are added outside of the tree.
Also, not very componentized.

2. Declarative but using components defined imperatively. CSS added in-tree as a modifier function.

3. Same as above but CSS is added outside of the tree.

Which one do you prefer? Any suggestions to improve?

==


a2800276

unread,
Jun 8, 2022, 6:06:53 AM6/8/22
to golang-nuts
To be honest: on first glance, they all look identical to me apart from the missing AddClass statements in the  last example.
Would it be possible to have some examples with less subtle differences?

¯\_(ツ)_/¯ sorry


atd...@gmail.com

unread,
Jun 8, 2022, 9:28:32 PM6/8/22
to golang-nuts
Hey,

Yes, they all look kind of similar because they all use function composition and are variations of the same tree, just not with the same level of expansion.

I've made a new gist that shows more distinct approaches.


Thanks for checking, it's really appreciated.

Henry

unread,
Jun 8, 2022, 11:59:04 PM6/8/22
to golang-nuts
Alternatively, you may experiment using structs with exported fields. It may be a bit less verbose.

atd...@gmail.com

unread,
Jun 9, 2022, 4:10:40 AM6/9/22
to golang-nuts
Someone did suggest implementing the tree using structs to reduce indentation. 
I thought about it. However, there is no inheritance (thankfully!) and types are invariant (no covariance/contravariance) in Go so I'm afraid it wouldn't compose. 
Unless I'm missing something? 
Reply all
Reply to author
Forward
0 new messages