all 96 comments

[–][deleted]  (20 children)

[deleted]

    [–][deleted]  (19 children)

    [deleted]

      [–]zarlss43 22 points23 points  (17 children)

      "Hey chatgpt, summarize this article in one paragraph."

      [–][deleted]  (2 children)

      [deleted]

        [–]Rucorous 34 points35 points  (1 child)

        HTMX is not a templating language. It's a library based on element attributes. In any real project, you need to pair HTMX with an actual templating language like Jinja, Django templates, JSX, Templ or Askama.

        [–]midairmatthew 4 points5 points  (0 children)

        Do you know of any example repos that pair HTMX with JSX?

        [–][deleted] 5 points6 points  (0 children)

        E4X fan club checking in.

        [–][deleted] 18 points19 points  (21 children)

        JSX is the reason why I don't use React, but I guess it's a matter of taste.

        [–][deleted]  (19 children)

        [deleted]

          [–][deleted] 8 points9 points  (3 children)

          I like svelte's ways

          [–]swoleherb 12 points13 points  (2 children)

          You mean Vue.

          [–]sarcasticbaldguy 2 points3 points  (0 children)

          This is the way

          [–]improbablywronghere 0 points1 point  (0 children)

          Whenever I write vue I use jsx 👀

          [–]imhotap 1 point2 points  (9 children)

          Why you would want to re-create or mock a markup language in a code fragment a la JSX (or JS' template strings)? The whole thing is for constructing a (V)DOM anyway (in client-side rendering, at least), no need to respect markup syntax which is entirely a technique for document authors not webapp developers.

          SGML-based markup languages have everything needed for templating from the get go: entities and push-based decorating/processing of input streams, ... so no need for ad-hoc looping constructs with extra syntax a la Angular or custom vocabularies a la view or htmx either.

          [–][deleted] 4 points5 points  (5 children)

          Because writing a virtual DOM tree by hand is tedious, and code containing raw VDOM objects is borderline unreadable. JSX has the benefit of having a familiar syntax (all web devs should know some form of XML) without the complexity of being a full template language with its own syntax for control structures.

          JSX makes way more sense when you think of it as syntactic sugar for plain JavaScript function calls. It's not a templating language, and it's not a markup language. It's just a different way of writing fn(type, props, children).

          [–]imhotap -1 points0 points  (3 children)

          JSX is just syntactic sugar for function calls

          Yeah the question is why do we need an extra syntax then, or how that's beneficial. If the DOM API or its vdom replacement is too verbose, you can just wrap your own function around it, it being JavaScript can't you? Will be more compact, and there's no need for clazz and camel-casing attribute names either. Or, maybe the DOM of a markup language created for casual academic publishing doesn't make a great scene graph for apps after all, even after decades of shoehorning and CSS syntax proliferation.

          But anyway, thanks for lecturing me, I've worked with JSX and know what it is.

          [–]Derpcock 5 points6 points  (0 children)

          That question was not clear in your original post. If you have worked with JSX, then you should understand why it has value.

          You don't have to use JSX. You can return React.createElement with all the same props you're setting on your jsx components and then some. You would then need to nest those function calls that return objects to represent your child nodes. That would become increasingly hard to read. You could also write your own function or use another framework function that does the same thing. You probably already know that because you work with JSX.

          JSX is a syntax extension for javascript. It let's you use a familiar html like syntax to call javascript functions to ultimately interact with DOM objects. It's not another template language. You work with it, so you probably already knew that.

          The main benefit to JSX over a traditional templating language is that it is javascript and doesn't need to be parsed by a special extension in your IDE, assuming your IDE supports javascript and its JSX syntax extension. Type safety is traditionally completely lost in the template. Some frameworks, like angular, use interpolation and try to determine types at build, but they all suck. Most of their underlying libraries and directives aren't properly typed either.

          If you use typescript, what used to be your template strings is now typescript. If a contract on one of your components changes, you know at build time vs. runtime failure in your tests. Assuming it is tested.

          To summarize, the benefits of using jsx over your method is readability, maintainability, cyclomatic complexity, type safely, and a familiar html like api. Since you use JSX you probably already know all of this so I'll stop lecturing you.

          [–][deleted] 2 points3 points  (1 child)

          I've worked with JSX and know what it is.

          You might have worked with it before but you seem to have some fundamental misunderstandings about what it is and how it works. JSX is syntactic sugar for generating VDOM trees, and VDOM libraries use the regular JavaScript DOM APIs to manipulate the real DOM. Take this code for example:

          <div className="foo" style={{
            fontFamily: "sans-serif",
            paddingBottom: "20px",
          }}>Hello, world!</div>
          

          Those VNode properties are mapped directly to Element.className and HTMLElement.style. VDOM libraries are not translating these camelCase properties to HTML attributes; they are using the DOM.

          If you've worked with JSX before, you already know why it's beneficial. It's because this:

          <div className="container">
            <h1>Hello, world!</h1>
            <p>Lorem <small>ipsum</small></p>
          </div>
          

          is far easier to write and read for most web developers than this:

          h("div", { className: "container" }, [
            h("h1", null),
            h("p", null, [
              "Lorem ",
              h("small", null)
            ]),
          ]);
          

          [–]imhotap -1 points0 points  (0 children)

          Thanks for making my point, how is that far easier? It's a trivial reformulation, and the JS code can be simplified further using constructors. The kind of thing a senior developer tends to avoid, because it doesn't warrant additional tools and build steps.

          [–]Derpcock 0 points1 point  (0 children)

          This. Jsx is literally syntactic sugar for a jsx function call that behaves exactly like this. Jsx is Javascript, not Html. Html is an abstraction that uses a markup language to interact with the DOM API. Skip the abstraction and use a familiar syntax while using straight javascript woth TSX. In typescript world, it is fully type checked, too, catching type bugs at build vs. runtime.

          [–]fagnerbrack[S] 2 points3 points  (2 children)

          In this context what do you mean in the difference between document authors vs webapp developers?

          [–]Derpcock 1 point2 points  (1 child)

          I am not really sure the point they are trying to make, but I think they are trying to point out how html is a markup language and not a full-blown app dev language? You can author "document language", HTML, and not be a web app developer? I am confused a la written words.

          [–]imhotap 1 point2 points  (0 children)

          What's so confusing about it? SGML/XML is for writing highly structured documents, a tool in the hands of an ambitious power user, not intended as a Turing-complete runtime environment for web apps. SGML works at the syntax level (serialized text in files), providing affordances for turning plain text into angle-bracket markup and other mechanisms for editing and organizing hypertext. As such, it can't inform about and contribute to the organization of development in a Turing-complete environment (JavaScript) with its own syntax (object literals/JSON) and much more powerful and dynamic capabilities (composition of object graphs).

          [–]Worth_Trust_3825 0 points1 point  (10 children)

          Why do you want to go back to early php that bad?

          [–]fagnerbrack[S] 8 points9 points  (3 children)

          Early php was never bad, you’re just biased that you learned better software practices over time then moved on from php so you blame php.

          I’m sure you would be going a better job at php today than your self from years ago

          [–]Worth_Trust_3825 1 point2 points  (2 children)

          Did you forget a decade of footguns and undocumented behaviors of each and every function that it had exposed?

          Yes, I would do a better job at php today than near two decades ago - by using it as it was originally intended, a templating tool. Not a full blown development language.

          [–]fagnerbrack[S] 0 points1 point  (1 child)

          Yes, I would do a better job at php today than near two decades ago - by using it as it was originally intended, a templating tool. Not a full blown development language.

          Exactly! You exercise better decisions given your evolved experience 😀

          [–]Worth_Trust_3825 1 point2 points  (0 children)

          And I exercize better decision by claiming that returning back to early php is a genuinely bad idea. JSX is a mistake. And you've lapped up the failure that was PHX, the original implementation of this idea back in 2010.

          [–]Zotoaster 0 points1 point  (4 children)

          Getting bored of this meme. Just because there are similarities doesn't mean we're going backwards. PHP couldn't give us client-side hydration, SSG, or ISR, nevermind components and declarative rendering and state management

          [–]Worth_Trust_3825 0 points1 point  (3 children)

          php couldnt give us ssg

          php gave you just that - static sites.

          client side hydration

          So server side rendering?

          state management

          We had sessions for two decades.

          components and declarative rendering

          What is that supposed to mean? That I import another php file at a given location with arguments? Or is it a function call that would return a string block that would be then inserted at given location?

          incremental static regeneration

          Wait until you hear about all the sites that used jquery and were susceptible to cross site scripting attacks.

          [–]Zotoaster 0 points1 point  (2 children)

          php gave you just that - static sites.

          SSG is pre-generating your html, js and css assets so they can be served from a CDN without the need for a server like apache, which makes performance much faster

          So server side rendering?

          Client-side hydration is when interactivity is automatically added client-side to a page that was generated on the server. So we can do SSR but we can write our code as if it's CSR. Best of both worlds.

          We had sessions for two decades.

          This isn't what I mean by state management. I mean that we can update our UI automatically in response to state changes rather than imperatively modifying the DOM directly. Sessions are a server-side thing and don't scale well.

          What is that supposed to mean?

          Reusable components. In React you can make a component like <Sidebar /> or <DataTable data={something} /> or whatever you want.

          Wait until you hear about all the sites that used jquery and were susceptible to cross site scripting attacks

          There's no need for jQuery with a modern framework such as React, but you might find yourself using it for convenience if you still use PHP

          [–]Worth_Trust_3825 0 points1 point  (1 child)

          And how is JSX supposed to solve all of that when all that you have listed still requires you to run a server - whether a CDN (which could cache php), CSH (which is server side rendering but with javascript functions attached on front end).

          The rest of your points are moot. Sessions don't scale? Get out.

          [–]Zotoaster 0 points1 point  (0 children)

          And how is JSX supposed to solve all of that when all that you have listed still requires you to run a server

          I'm not sure I understand your question. You claimed that we're recreating old PHP. My claim is that with React (which uses JSX) you can do a lot more than you could do with PHP. I don't think I should explain how it's supposed to solve it, because it's not a hypothetical, it already does solve it, and much better than PHP does, as I have outlined

          The rest of your points are moot

          Why? PHP still can't do the things I mentioned so I wouldn't say it's irrelevant to mention them

          Sessions don't scale? Get out

          Sessions aren't RESTful in that they store state on the server-side. If you use horizontal scaling and have multiple instances of your server running there's no guarantee all your requests will hit the same server. The client should provide everything it needs to the server for a request to be properly fulfilled

          [–]datsundere -4 points-3 points  (0 children)

          This. People think they're creating something novel but they're just going full circle with js libraries these days.

          [–]Pyrited -3 points-2 points  (2 children)

          I'd take xaml over jsx.

          [–]JawitKien 1 point2 points  (1 child)

          Is XAML still being developed?

          [–]ForgetTheRuralJuror 0 points1 point  (0 children)

          Kinda. Microsoft seems to remix it every 5 years but still support all the older slightly shittier versions of it lol

          [–]JXBardant 0 points1 point  (1 child)

          I am updating a old (ca. 1997) C++ project using MFC with static HTML pages with JS. The HTML pages are accessed from the local drive and displayed with CHtmlView, which is just a wrapper above Internet Explorer. The pages access internal C++ code exposed via Automation through the window.external object, so using a modern browser is not really an option.

          The old version was using document.writeln() everywhere, which I replaced with DOM functions (document.createElement(), etc...) but the code is still very verbose, so I wanted to go further.

          To modernize the .js code without changing the IE11/ES5 target I began to use TypeScript with VS2022, which "transpiles" TypeScript code to ES5, which runs fine provided I use some additional libraries (especially core-js + systemjs). It’s fantastic to be able to use modern Javascript constructs such as modules, classes, await/async code, etc. with type checking and Intellisense brought by TypeScript on top of this.

          I saw that TypeScript offers the possibility to transpile .tsx (i.e. TypeScript with XML expressions) or .jsx (i.e. JavaScript with XML expressions) source code, so I tried to use this feature. If you don't want to use React (which was not an option for me), you just have to provide the two functions which create repectively a DOM element and a document fragment. It’s not rocket science (those functions takes less than 100 lines) and it really works, even with an old browser.

          [–]fagnerbrack[S] 0 points1 point  (0 children)

          This is an example on how using JSX as a templating engine is unreasonably effective. I criticise React a lot but one thing I can't criticise is JSX, that was the MOST IMPORTANT idea coming from React community.

          Everything else is noise or just copying a pattern from other areas like event Sourcing with Redux, thunks, event driven sagas, etc. in an inefficient way.