←back to thread

378 points rbanffy | 1 comments | | HN request time: 0.203s | source
Show context
giancarlostoro ◴[] No.46210692[source]
Template partials look good, which is one of the key reasons frameworks like React are as good and popular as they are, because you can reuse small segments of code.
replies(8): >>46211187 #>>46211247 #>>46211354 #>>46211402 #>>46211982 #>>46212701 #>>46212849 #>>46213424 #
littlecranky67 ◴[] No.46211982[source]
Key benefit for reusability and composability in React is IMHO that they don't use templates at all, but everything is a function.
replies(1): >>46214928 #
globular-toast ◴[] No.46214928[source]
Exactly. There are a few libraries to achieve a similar thing in Python:

* https://htpy.dev/

* https://pypi.org/project/fast_html/

* https://fastht.ml/ (different to above, I think)

* https://github.com/volfpeter/fasthx

Probably others. I strongly prefer this to templating, but I find it makes dyed in the wool Django people squirm.

replies(3): >>46216164 #>>46216606 #>>46216700 #
Induane ◴[] No.46216164[source]
There are a lot of cool things about these, one that they are less typo prone and also they are often much faster.

The downside is I find them hard to read.

I think the template approach isn't quite right and yet neither is the functional approach.

At the end of the day these are a type of tree structure; I think we could conjure a new mechanism that gets the best of most/both worlds.

replies(1): >>46216671 #
1. globular-toast ◴[] No.46216671[source]
Yeah, I agree, I find them hard to read. JSX is the best thing I've used. Elsewhere in the thread someone mentioned Cotton which seems to strike a different balance.

To be honest my main problem with templates is they have to be one per file. In principle there's no difference between naming a new file and naming a function, but in practice it just sucks. It's a higher barrier so people are less likely to write smaller components, and refactoring support completely sucks. Even renaming a template is a massive pain whereas renaming a function with decent LSP support is easy.

JSX hits that perfect balance between readability while still being regular functions. Maybe something is possible with the new 3.13 template strings?