Live data from Hacker News

Maud: A Rust macro for writing HTML

maud.lambda.xyz

11–20 of 86 posts

Re: Maud: A Rust macro for writing HTML

#12
post #2

The main problem with macros like this (aside from being yet another language to learn) is that they don't work nicely with IDEs.

Shouldn’t it work in any IDE that understands Rust macros?

You can't build an IDE that definitely just "understands Rust macros" since procedural macros in particular are in effect modifying your compiler. Maud is a proc macro.

Mara's whichever_compiles! macro for example: https://github.com/m-ou-se/whichever-compiles -- that macro is forking your compiler to try out all the branches and throwing away branches which caused a compile error.

Clearly your IDE should throw its hands up and say, I don't understand what this does, I give up.

In general doing something useful with Rust macros is a more tractable problem for an IDE than say the C pre-processor, because Rust's macros have a stronger syntax, but the proc macro is potentially much too powerful / dangerous to try to evaluate.

Re: Maud: A Rust macro for writing HTML

#13
post #8
post #2

The main problem with macros like this (aside from being yet another language to learn) is that they don't work nicely with IDEs.

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).

Re: Maud: A Rust macro for writing HTML

#14
post #3
post #2

The main problem with macros like this (aside from being yet another language to learn) is that they don't work nicely with IDEs.

Isnt it just easier to have a html file then replace tags inside of that rather than having a new macro language ?

SGML (the markup meta-language once used for describing HTML) has that, but as we're talking the verdict is still out whether that's actually easier [1] ;) But anyway, SGML gives you HTML-aware, context-dependent, injection-free templating (even with hard support for sanitizing user content) in a content authoring workflow independent from a hosting programming language so is in a different ball park.

[1]: https://news.ycombinator.com/item?id=31637910

Re: Maud: A Rust macro for writing HTML

#15

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.

I wish it was still the consensus among JS devs. People are putting css into JS files, on top of html

Re: Maud: A Rust macro for writing HTML

#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 templating libs aren't that great comparatively.

Re: Maud: A Rust macro for writing HTML

#19
post #15

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.

I wish it was still the consensus among JS devs. People are putting css into JS files, on top of html

I think it isn't the consensus anymore because there isn't actually a "correct" solution. It's too subject to personal preference. For example, I prefer having HTML + CSS + JS all in the same file because then I know everything relevant to the component or page I'm working on is right there. I do concede that it can get extremely unwieldy if you don't separate out components though.

Re: Maud: A Rust macro for writing HTML

#20
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/docs/introducing-jsx.html

[2] https://github.com/scala/scala-xml

Post reply on HN