Live data from Hacker News

Show HN: Gomponents, HTML components in pure Go

gomponents.com

11–20 of 50 posts

Re: Show HN: Gomponents, HTML components in pure Go

#11

are event handlers possible? neither the Github repo nor the linked page showed an example of a button or form submission.

If you mean “action=/foo” for a “form” tag, there is an “Action” attribute: https://github.com/maragudk/gomponents/blob/main/html/attrib...

Re: Show HN: Gomponents, HTML components in pure Go

#12

So I like the idea of it but am feeling a bit wary about UI elements as runtime types. Good thing about this is the strong typing but then you have a fair bit of lispifying going on which I swing back and forth on. I actually like templ's approach on this (though hate the extra build step). So I finally just settled on plain old go templates. Not quite eloquent but just feels staple and simple. Clearly a lot of get o…

I agree with you, but I like Gomponents over html templates due to the type safety. It's also easier to reason about with. Some of my html templates can get quite difficult to maintain, with often the context not being obvious.

Re: Show HN: Gomponents, HTML components in pure Go

#13

So I like the idea of it but am feeling a bit wary about UI elements as runtime types. Good thing about this is the strong typing but then you have a fair bit of lispifying going on which I swing back and forth on. I actually like templ's approach on this (though hate the extra build step). So I finally just settled on plain old go templates. Not quite eloquent but just feels staple and simple. Clearly a lot of get o…

I agree with you, but I like Gomponents over html templates due to the type safety. It's also easier to reason about with. Some of my html templates can get quite difficult to maintain, with often the context not being obvious.

Totally. I am also in this journey where I keep going back and forth between templates and something typed. I really need something like native jsx inside go. Gosx anybody?

Re: Show HN: Gomponents, HTML components in pure Go

#14
While acknowledging the use case of "the designer who doesn't know how to program" and the desirability in some sense of separating logic from data, if I am going to slam together some HTML as a programmer, with no "non-programmer" designer in sight, I tend to slap together a local version of templates like this if I can't find a good one available. The reason is, if I'm going to mix logic and presentation anyhow, why bother with a template library that is basically an inner-platform, when I can just use the programming language itself? Then you get other integrations as useful, e.g., do you have some concept of interfaces/traits/whatever? Define a useful default representation for something and you can push it straight out in a template. This may not work for large UI elements, but in terms of "hey, here's how you display a Username in general" it can be useful, and it's not like you're stuck with only that way of rendering an object.

Closures, modules, functions, loops or recursion, conditionals, every feature of your programming language just right there, without some large templating library in the way. Debug your templates with the actual debugger. Very high performance with just a bit of care in the API design. Every programmer in your language can pick this up very quickly with hardly any effort and doesn't have to learn yet another complete templating language to start using your project, it's just comparable to picking up an API.

So many advantages... it's just... you have to be programmer if you want to modify the resulting code. Other than that, and I guess the fact you need to implement whatever discipline you may want on your own[1]... but those are a total killer in many cases.

[1]: This approach does not require that you mix presentation and logic, but if you want that separation, you will need to discipline yourself to maintain it. Though I have to admit, 25 years of programming on the web and I'm frankly still unconvinced by this argument, or, at least, unconvinced that it is the absolute most important thing in every context and only a cretinous lunatic would dare mix logic and presentation. It seems to me to be a rule espoused by far more people than it is followed by.

Re: Show HN: Gomponents, HTML components in pure Go

#15
post #14

While acknowledging the use case of "the designer who doesn't know how to program" and the desirability in some sense of separating logic from data, if I am going to slam together some HTML as a programmer, with no "non-programmer" designer in sight, I tend to slap together a local version of templates like this if I can't find a good one available. The reason is, if I'm going to mix logic and presentation anyhow, wh…

[deleted]

Re: Show HN: Gomponents, HTML components in pure Go

#18

are event handlers possible? neither the Github repo nor the linked page showed an example of a button or form submission.

It looks like this is focused on server rendering HTML, no client-side runtime or anything like that.

I don't see any used of a `Script()` function or similar in the example apps, though you could always chunk some JS in a public directory and link it in the HTML.

They do have a starter example that uses HTMX. That'd be my go-to as well for a tool that's sticking with server rendering HTML.

Re: Show HN: Gomponents, HTML components in pure Go

#19

So I like the idea of it but am feeling a bit wary about UI elements as runtime types. Good thing about this is the strong typing but then you have a fair bit of lispifying going on which I swing back and forth on. I actually like templ's approach on this (though hate the extra build step). So I finally just settled on plain old go templates. Not quite eloquent but just feels staple and simple. Clearly a lot of get o…

I agree with you, but I like Gomponents over html templates due to the type safety. It's also easier to reason about with. Some of my html templates can get quite difficult to maintain, with often the context not being obvious.

I started with html/template, but got fed up with it because I thought it was so hard to pass data around to different components. I don't know, I just didn't jell with it.

Re: Show HN: Gomponents, HTML components in pure Go

#20

Earlier quoted context omitted.

I agree with you, but I like Gomponents over html templates due to the type safety. It's also easier to reason about with. Some of my html templates can get quite difficult to maintain, with often the context not being obvious.

Totally. I am also in this journey where I keep going back and forth between templates and something typed. I really need something like native jsx inside go. Gosx anybody?

Isn't that basically Templ [0] then? But Templ has that extra build step for preprocessing and converting back to plain Go files.

For me, gomponents is the middle ground. You don't get everything, but quite a lot of JSX-like feel. I was inspired by JSX after all. :) [1] Although I called it GOX back then… :D

[0]: https://templ.guide [1]: https://www.maragu.dk/blog/gomponents-declarative-view-compo...

Post reply on HN