4 ms·
Your dislike for ‘templates’ is much more a matter of personal preference than you’re letting on. Using language like “still using templates” makes me think tha
by KyeRussell 4y ago
Your dislike for ‘templates’ is much more a matter of personal preference than you’re letting on. Using language like “still using templates” makes me think that you don’t see any valid opposing view.
I do not like JSX. It’s not worth talking about why. It’s not an argument I want to have. But framing non-JSX approaches as objectively inferior is not in tune with the reality, being that this is something sensible people disagree on.
- wokwokwok 4y ago> Templates are a no go for me It’s pretty hard to get more “this is my opinion rather than a statement of objective fact” than this. > I do not like JSX. It’s not worth talking about why. It’s not an argument I want to have. Ok. Um… well, it’s hard to have a discussion if you won’t talk about it… …but, “code” templates allow autocomplete and type checking in a way that is an objectively distinctive superset of text templates. It’s because they are code. A template is (almost always) a weakly typed DSL. Written, ignoring all the history of language design… by a bunch of folk who don’t really know how to write programming languages. …and, they. Are. Bad. Not always… but often. …because writing a language is hard, and because (reason) you can’t ever use an existing template language. Oh no. This framework has to have its own unique one, because otherwise it doesn’t integrate tightly. Do you like DSLs? Or do they just hide the complexity somewhere else? What if the DSL is bad, not orthogonal in its feature set, poorly implemented …but cute, and useful for a very very narrow use case. Isn’t the main critique of react that it hides complexity by moving it from one place to another? Don’t you think it’s a tiny bit ironic that all the other templates based languages with their custom template DSLs are doing the same thing? Anyway; I think it’s fair to evaluate template languages as what they are: DSLs. JavaScript is a better language than most template languages by a variety of metrics. Other languages are better than JavaScript, absolutely… but, never, have I seen a template language that is. You can love declarative configuration all you want, but it’s very very difficult to argue that just because you can make a mess with procedural approaches that they are worse; because they are a strict superset of what’s possible using the declarative approach. …so sure. I don’t but “JSX is easier to maintain”, but it’s distinctly superior in capability.
- uranusjr 4y agoJavaScript is a better, but JSX is not JavaScript. It reuses many features from JavaScript, but you still need some sort of translation (compilation) step to make it useful. In this sense it is not really fundamentally different from any of those what you call template languages. You can argue the fact JSX better integrates syntaxes from a proper programming language makes it better than other templating languages (and I’m not going to try persuading you otherwise), but the “JSX is better than template language because it is not one” stance you’re implying won’t help you win any arguments.
- wokwokwok 4y agoIt is javascript. That is literally the difference between JSX and most other template languages. Look it up. The template syntax is converted to literally code and evaluated. The <> are just syntax sugar. How did you imagine the inline code works? The in-line function declarations? Did someone invent a mini-subset of JS as DSL and a custom runtime…? Don’t be ridiculous. They did not. JSX is literally a thin wrapper around actual code.
- uranusjr 4y agoTemplate language being translated to code is nothing new and certainly not unique to JSX even only when you consider frontend JavaScript frameworks. Vue has been doing that ever since single-file component was a thing. You need to look up things, please.
- prmph 4y agoStrongly agree. I just don’t get the hate for JSX. JSX is objectively better than than the scores of custom DSL templating systems out there. If anything, I think JSX is not used and supported enough. In the most general sense, JSX is just syntactic sugar for function composition. That it works well for html components is a side effect; it could certainly be used for more than that. I
- jmull 4y agoI have no idea why JSX wouldn't be considered a DSL template language? I guess there are specific features you find compelling: it's typed, has good tooling for completions in your editor? These exist in other template languages, and ones that transform more readily to HTML (which is the goal, don't forget). Maybe you also value that it has a straight-forward, well-defined transformation to javascript? That's OK, but since HTML is the goal, it doesn't seem right to optimize for an intermediate representation. To me it's a weakness of react that you have to work with HTML as javascript (which JSX mitigates fairly well, but is hardly ideal). If you want to have it all, try Svelte.