Live data from Hacker News

Maud: A Rust macro for writing HTML

maud.lambda.xyz

31–40 of 86 posts

Re: Maud: A Rust macro for writing HTML

#31
post #30
post #29

Earlier quoted context omitted.

> One of the huge advantages of Maud is that it keeps code and markup close together I'd say it's actually a disadvantage. Front end engineers will work with HTML with embedded logic (as little as possible - values, iterators, conditionals). Generating HTML from Rust code is nice for simple things, but won't work with complicated HTML templates when those are required and will be harder to integrate with front-end ap…

My projects have no front-end engineer, however. The frontend is written in Rust as well and also uses Maud for HTML templating. And I dispute it not working with complicated HTML templates, that's handling it fine and integrates very well since I share code between frontend and backend anyway.

I get that, but Maud is not the first of its kind and the absence of similar engines in web development is a telltale sign it's not the optimal approach.

Re: Maud: A Rust macro for writing HTML

#32
post #31
post #30

Earlier quoted context omitted.

My projects have no front-end engineer, however. The frontend is written in Rust as well and also uses Maud for HTML templating. And I dispute it not working with complicated HTML templates, that's handling it fine and integrates very well since I share code between frontend and backend anyway.

I get that, but Maud is not the first of its kind and the absence of similar engines in web development is a telltale sign it's not the optimal approach.

Well, as mentioned, I've yet to find something that can replace Maud without sacrificing it's advantages (in-code inheritance, code-sharing and compile-time type-safety).

So even if it's not the "optimal approach" as you title it, it's the ergonomic approach for me because it doesn't get in my way.

Re: Maud: A Rust macro for writing HTML

#33
post #23

People like to hate everything related to JS these days. But when I see libs like these I'm just very grateful for the person(s) who invented JSX [1]. And evenly for MSFT implementing it into TS as a first-class citizen. It's just so much more readable. Scala is the only other language I know of which has some kind of XML/HTML syntax support (scala.xml). (But it looks like it got removed. [2]) [1] https://reactjs.org…

IIRC php/hack had it before jsx existed: https://docs.hhvm.com/hack/XHP/introduction https://github.com/phplang/xhp

That's actually the heritage of JSX!

XHP was launched in 2010 (https://www.facebook.com/notes/10158791323777200/)

The first version of FaxJs (the precursor to React) was launched in 2011, being directly inspired from XHP (https://github.com/jordwalke/FaxJs)

React was made in 2012 by the same person who made FaxJs, taking the best ideas from FaxJs and creating React.

So yeah, JSX actually comes from the idea of XHP :)

Re: Maud: A Rust macro for writing HTML

#34
post #23

Earlier quoted context omitted.

IIRC php/hack had it before jsx existed: https://docs.hhvm.com/hack/XHP/introduction https://github.com/phplang/xhp

That's actually the heritage of JSX! XHP was launched in 2010 ( https://www.facebook.com/notes/10158791323777200/ ) The first version of FaxJs (the precursor to React) was launched in 2011, being directly inspired from XHP ( https://github.com/jordwalke/FaxJs ) React was made in 2012 by the same person who made FaxJs, taking the best ideas from FaxJs and creating React. So yeah, JSX actually comes from the idea of XH…

https://github.com/facebookarchive/xhp-php5-extension if you are interested in seeing how Marcel initially implemented XHP for PHP.

The concept was popular at Facebook, so it made its way into HPHP, HHVM, and later ReactJS.

Re: Maud: A Rust macro for writing HTML

#35
post #16

Maud is wonderful for small things like a stats page or dashboard. But once you start getting to a few pages it's so much less cognitive overhead to separate concerns out into proper html files/templating. It seems quite daunting to have a large project where all your html is inside rust files and a lot harder to find people who can work on it proficiently.

One of the huge advantages of Maud is that it keeps code and markup close together, so you can do things like having rust control structures determine what markup is used later on (for snippets or widgets, for example). Plus, Maud has a definitive speed advantage from what I've noticed. Sadly, there isn't any great alternative for making performant HTML templates in Rust from what I've seen, a lot of the other HTML t…

Askama should be comparable in speed and type safety? It probably doesn't integrate any better inline with source though (I've only used it with standalone template files).

https://djc.github.io/askama/creating_templates.html#the-tem...

Regardless, it's good to see some variety and experimentation like Maud in software design

Re: Maud: A Rust macro for writing HTML

#36

People like to hate everything related to JS these days. But when I see libs like these I'm just very grateful for the person(s) who invented JSX [1]. And evenly for MSFT implementing it into TS as a first-class citizen. It's just so much more readable. Scala is the only other language I know of which has some kind of XML/HTML syntax support (scala.xml). (But it looks like it got removed. [2]) [1] https://reactjs.org…

I don't think JSX is very readable. If you squint it may look like HTML, but when you try to actually read it, it's all off. Different attributes, bizarre templating, blurred line between rendering and code. The latter in practice is always a complex mix of view/state/ callbacks with react.

Re: Maud: A Rust macro for writing HTML

#37

Earlier quoted context omitted.

I find that very interesting, I have the opposite reaction to JSX. Not wanting to use it has been one of the biggest reasons I have moved into using ClojureScript/Hiccup for front-end applications. I find JSX extremely hard to read and work with and reason about.

After you get a taste of the free world of hiccup/reagent where it's just vectors and maps to create HTML, its really hard to imagine going back to anything else. Being able to use the same programming language in your "HTML template" (which are just core data structures in a specific shape) as for the rest of your programming is just icing on the top. Small example for people to understand the difference: // HTML &…

I think the big differences don’t come out visually.

In JSX you might be struggling with expressing certain things, because JS has a statement expression syntax. So you have to circumvent that. In Clojure everything is an expression already.

In JSX you can manipulate components with HoCs. In Clojure it’s just data, no special ceremony needed.

On the client, if you’re using React, you might use hooks to keep travk of state, which are a special construct that don’t exist in JS. In Clojure, if you use something like reagent, you just use atoms, they have a special purpose implementation, but they look and feel like regular old atoms.

However I have to say, JSX and React are very productive even with those limitations, simply because the tooling around it is so good.

Re: Maud: A Rust macro for writing HTML

#38
post #8

Earlier quoted context omitted.

Totally agree, macros are the worst Rust feature for me, they are way too powerful and break the tooling, e.g. fmt or language server. https://rust-analyzer.github.io/blog/2021/11/21/ides-and-mac...

It ultimately depends on how they're written. println! is a macro, and doesn't "break the tooling". on the other end of the spectrum, using a crate like demonstrate (unit testing) produces hard to understand errors and slows down the IDE. I don't remember experiencing Rust Analyzer crashes for a long time, though (I do remember some in the past).

println! is only a declarative macro, whereas Maud is a proc macro.

The declarative macros aren't too head-twisting for tools, they just expand as declared, this can sometimes have a few surprising effects but generally it is very manageable. Procedural macros have essentially unlimited power and thus are sometimes entirely impossible to analyse.

Re: Maud: A Rust macro for writing HTML

#40

People like to hate everything related to JS these days. But when I see libs like these I'm just very grateful for the person(s) who invented JSX [1]. And evenly for MSFT implementing it into TS as a first-class citizen. It's just so much more readable. Scala is the only other language I know of which has some kind of XML/HTML syntax support (scala.xml). (But it looks like it got removed. [2]) [1] https://reactjs.org…

I don't think JSX is very readable. If you squint it may look like HTML, but when you try to actually read it, it's all off. Different attributes, bizarre templating, blurred line between rendering and code. The latter in practice is always a complex mix of view/state/ callbacks with react.

You're confusing JSX and the React target for JSX; only the latter has the problems you mention.

This is a very common confusion because most people approach JSX via React, and as such never really grasp that JSX is a separate, independent thing. If you're interested in learning it standalone, I'd highly recommend working with either the Typescript `jsxFactory` compiler option, or the `@babel/plugin-transform-react-jsx`

Post reply on HN