5 ms·
The main problem with macros like this (aside from being yet another language to learn) is that they don't work nicely with IDEs.
by IshKebab 4y ago
The main problem with macros like this (aside from being yet another language to learn) is that they don't work nicely with IDEs.
- yakubin 4y agoThey also slow down compilation.
- dustymcp 4y agoIsnt it just easier to have a html file then replace tags inside of that rather than having a new macro language ?
- josephg 4y agoThis also supports conditional expressions and loops: https://maud.lambda.xyz/control-structures.html https://maud.lambda.xyz/control-structures.html
- fredrb 4y agoSo does most templating languages.
- tannhaeuser 4y agoSGML (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 https://news.ycombinator.com/item?id=31637910
- coffeeblack 4y agoShouldn’t it work in any IDE that understands Rust macros?
- msk-lywenn 4y agoIs there any? I don't think there is a real meaning to "understanding rust macros", as they define something completely new.
- tialaramex 4y agoYou 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 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.
- czei002 4y agoTotally 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-macros.html https://rust-analyzer.github.io/blog/2021/11/21/ides-and-mac...
- pizza234 4y agoIt 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).
- tialaramex 4y agoprintln! 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.
- pornel 4y agoprintln! depends on a proc macro: https://doc.rust-lang.org/stable/src/core/macros/mod.rs.html#902-907 https://doc.rust-lang.org/stable/src/core/macros/mod.rs.html...
- tialaramex 4y agoI see a built-in there. Are you really seeing a proc macro?
- shepmaster 4y ago> println! is a macro, and doesn't "break the tooling" I like, use, and write macros, but this isn't fully true. For example, recent Rust versions allow writing identifiers directly in the format string: println!("{some_identifier}") However, this breaks rust-analyzer's ability to rename variables [1]. [1]: https://github.com/rust-lang/rust-analyzer/issues/11260# https://github.com/rust-lang/rust-analyzer/issues/11260#