Wouldn't it be better to use Domain-specific types everywhere (e.g. Duration instead of f32/f64)? #1124
Unanswered
quadruple-output
asked this question in
Q&A
Replies: 1 comment
-
I like this from a code quality perspective. When implementing these sorts of things in my own toy projects, the approach I take is: struct Angle(f32);
impl From<f32> for Angle{
from(float : f32) -> Self{
Angle{float)
}
} This keeps the syntax clean, but also enforces stronger type safety and allows for new From impls (like from f64) and utility methods directly on that type. I could see a small runtime penalty due to a) indirection b) repeated conversion, but I'm skeptical that either effect is large and the latter can be mitigated through a bit of stylistic discipline. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Summary: Is it by intend that there are some functions in bevy which return durations as plain floats only? Wouldn't it be better to use the
Duration
type by default wherever possible? The same question applies to other domain specific types, for example angles.I just updated my little project to bevy 0.4 and replaced the standard scheduling by FixedTimestep scheduling. When adapting my existing code, I found that FixedTimeStepState::step() returns an f64, but not a Duration. This feels like a step backward when adapting code which was previously based on Time::delta() (which returns a Duration).
Is there any runtime penalty attached to using Duration?
Similar case: Quat::from_rotation_y() expects an f32 as argument. I feel it would be much nicer to use a dedicated Type for angles. Is there any such thing in Bevy, and shouldn't it be used in favor of f32?
Beta Was this translation helpful? Give feedback.
All reactions