Replies: 3 comments
-
This use of macros often makes code much harder to understand for intermediate and advanced users, and can lead to a lot of tech debt as you build, debug and sort out the macros needed to work with it. It also badly breaks tooling, like rust-analyzer, that is widely used when reading Rust code. For patterns like that, I much prefer the use of getters and setters with clearly documented constraints, or even better, storing those constraints in the type system :) |
Beta Was this translation helpful? Give feedback.
-
Restrictions like those don't make much sense for systems (which might be the functions that you have in mind) since their arguments are based on the state of the world. What would you do if the state of the world doesn't comply with the restrictions? Panic? They make more sense in components and resources. But since you are in control of setting and updating the values of your components, you don't need official support for this kind of thing. And as Alice pointed out, there are alternative approaches and each developer can choose their preferred ones. |
Beta Was this translation helpful? Give feedback.
-
Thanks, @alice-i-cecile and @Pascualex! All of your explanations make sense to me, and I’ll try to remember these points as I continue learning and tinkering. 👍 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What problem does this solve or what need does it fill?
Bevy clearly tries hard for a human-friendly API.
I'm still new to both Bevy and Rust. That said, I noticed that this other Rust project uses macros on individual
fn
parameters in a way that makes reading the code delightfully understandable.What solution would you like?
I feel that I am not yet familiar enough with Rust to make a specific recommendation, but just take a look at the linked code, and think about where syntax like that might make it easier to write—and more importantly read—bits of code with Bevy.
What alternative(s) have you considered?
None. I have much to learn. Just appreciating a use of attribute macros on parameters, which I hadn't seen before. ☻
Beta Was this translation helpful? Give feedback.
All reactions