maxence-charriere/go-app

Modify tag building so that we can avoid calling Body()

JulienLecoq opened this issue · 4 comments

Having to call Body() every time we want to build an html tag feels verbose for no reason.
Wouldn't it be better to be able to do:

s := app.Span()
app.Div(s)

Instead of:

s := app.Span()
app.Div().Body(s)

The code is less verbose and more readable using the first approach.

Thats mean all the attributes and event handlers are set after the body which feels less readable in my opinion.

Maybe we could keep the Body method for those who prefer your way but also add "my" way for the others?
But that would introduce two ways of doing basically the same thing, so that's maybe not the best.

@JulienLecoq Maybe write up some larger code examples here and show the difference and why your way helps with coding. We wrote lots of Go-App style HTML code and do not see a problem with the current method. What Maxence is pointing out is what I would fear too: You can't see the attributes that way without scrolling down to closing parenthesis and I think this may make it hard to make adjustments to the code. Especially with large structures that are nested multiple levels.

P.S.: You do not have to call body for every HTML tag. There is a lot of code app.Div().Class("....").Text("....") and similar with other elements.

P.P.S.: Before I saw what Go-App is doing I was following https://www.gomponents.com/ development for some time. Right now I like the Go-App way better. We can read and reason about it very easily in the team too.

But that would introduce two ways of doing basically the same thing, so that's maybe not the best.

You said it all :)