Live data from Hacker News

Maud: A Rust macro for writing HTML

maud.lambda.xyz

21–30 of 86 posts

Re: Maud: A Rust macro for writing HTML

#21

Quoted post unavailable.

Most languages don’t have macros powerful enough to do this.

What? Outputting HTML is basic enough that most languages don't need to use macros for this.

I don't understand why'd you want to use macros with all its problems to generate HTML, when even a simple data structure like "vectors in vectors" would do just fine to generate HTML (ala Reagent in Clojure-land).

Re: Maud: A Rust macro for writing HTML

#22

Earlier quoted context omitted.

Most languages don’t have macros powerful enough to do this.

What? Outputting HTML is basic enough that most languages don't need to use macros for this. I don't understand why'd you want to use macros with all its problems to generate HTML, when even a simple data structure like "vectors in vectors" would do just fine to generate HTML (ala Reagent in Clojure-land).

That's a bit not fair to languages different than lisp because of their more complicated syntax.

Clojure simplicity is just superb in this case.

Re: Maud: A Rust macro for writing HTML

#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

Re: Maud: A Rust macro for writing HTML

#24
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…

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

Which others have you tried, and why do you think they're not great?

Re: Maud: A Rust macro for writing HTML

#25

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

Re: Maud: A Rust macro for writing HTML

#26
post #16

Earlier quoted context omitted.

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…

> 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. Which others have you tried, and why do you think they're not great?

I've tried handlebars and liquid. They're okayish, but both slow and don't have any compiletime help or typing when I tried them.

Horroshow, ructe, typed-html and yarte were okay but inheritance was underdocumented (or generally not as well documented), which is a big no for me. And a few only give minor-quality help at compile time.

Maud on the other hand has decent compiletime help and doesn't require a lot of documentation as normal rust code is doing the heavy lifting.

Re: Maud: A Rust macro for writing HTML

#27

Earlier quoted context omitted.

What? Outputting HTML is basic enough that most languages don't need to use macros for this. I don't understand why'd you want to use macros with all its problems to generate HTML, when even a simple data structure like "vectors in vectors" would do just fine to generate HTML (ala Reagent in Clojure-land).

That's a bit not fair to languages different than lisp because of their more complicated syntax. Clojure simplicity is just superb in this case.

Arrays/sequences/vectors or a similar implementation of those exists in most languages, lisps are not unique in that way :)

Re: Maud: A Rust macro for writing HTML

#28

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 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 & JSX
    
      Niko
    
    
    // Hiccup
    [:div#person
      [:h1 "Niko"]]

Re: Maud: A Rust macro for writing HTML

#29
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…

> 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 applications. It's possible to compile a template with embedded logic (Java Server Pages did that in the late 1990's) to performant and type safe code. An approach like that would be great for Rust (someone must have done it by now)

Re: Maud: A Rust macro for writing HTML

#30
post #29
post #16

Earlier quoted context omitted.

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…

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

Post reply on HN