this post was submitted on 10 Aug 2025
832 points (95.0% liked)
Programmer Humor
25671 readers
2329 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I great example I saw is a dev who was building on a Rust game (with the Bevy engine), and switched to Unity.
https://deadmoney.gg/news/articles/migrating-away-from-rust
It sounds like Rust (game engines, and more) could use a higher level scripting language, or integrate an existing one, I guess.
I interface with low level communication protocols, mostly uart, so it fits my use case. But it is nice to see the hurdles people encounters. It tells a lot about the language.
Yeah. I wasn't trying to imply it's a bad language at all; it just fits certain use cases. They are complex, like people.
Still, it seems like it'd be cool for engine work, with C# or maybe a subset of typed Python as a scripting language.
One approach is to use more macros. These are still rooted in the core Rust language, so they give up none of the compile-time checks required for stability. The tradeoff is more complex debugging, as it's tough to implement a macro without side effects and enough compile-time feedback that you'd expect from a DSL.
Another is to, as you suggest, embed something. For example, Rust has Lua bindings. One could also turn things inside out and refactor the rust program (or large portions of it) as a Python module.
Are Rust macros akin to the C macros? Basically an inline replacement of a code section?
Kind of. They do center on code generation, at the end of the day. That's where the similarities end. You can't insert macros into your code arbitrarily, nor can you generate arbitrary text as an output. Rust macros take parsed tokens as input, and generated (valid) code as output. They must also be used as annotations or similar to function calls, depending on how they're written. The limitations can be frustrating at times, but you also never have to deal with brain-breaking
#define
shenanigans either.That said, I've seen some brilliant stuff. A useful pattern is to have a macro span a swath of code, where the macro adds new/additional capabilities to vanilla Rust code. For example, here's a parser expression grammar (PEG) implemented that way: https://github.com/kevinmehall/rust-peg