-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented num traits for Val #5555
Conversation
Also fixes #5456 because I thought this tiny change didn't warrant a separate PR |
Can you split this out? I see your point, but it'll keep the commit history cleaner and make sure that it doesn't get held up in review : |
I'm quite happy with these as rules; they're both intuitive and teachable. Can you document this in the |
I don't know if I like that idea. It seems very prone to cause hard to find bugs. I'd much prefer at least logging a warning, but I wouldn't be against straight up crashing. Trying to operate on incompatible value should always be a bug in my opinion. I also think this should be the behaviour when operating on anything that isn't an exact match on both side. |
Removed |
I have to agree, operating on incompatible values should be a bug. But before making things crash I'd prefer to not have these math traits implemented at all for If we're expecting this not to be a big issue in practice I'll add the warnings for now and the docs. If we want to change it to panic then we'd have to think about the num traits with |
Also while we're at it, if I remember correctly from my CSS Flexbox experience, the default value for a flexbox is |
I added the docs for now. |
Yep :) I'm not entirely sure what the right behavior is, so I've slapped on a Controversial label. |
I like the idea, but this has the risk of making it possible to operate on px and percent at the same time without the compiler catching it, but I like that it would force people to convert the value. Personally I still prefer the current approach as long as it at least logs a warning when incompatible types are used because it makes it impossible to operate on incompatible values. |
I mean people can always manually take out values from pixel and percent and do whatever they want to them. No way of preventing that. But ok I’ll add warnings then. I guess I’ll add them as well to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation looks good but like the others I'm a bit hesitant to allow users operate on incompatible types.
- Can we come up with any kind of sample code where it would be valid to add incompatible types?
- If yes and the use-case makes sense then I'm happy to leave it as is (maybe emit warning)
- If no, then we should just panic until someone has a real situation where this panic breaks their code and they can make a good case for why we should no longer panic?
I'm very reluctant to introduce insidious panics in basic operators. I think it's a mistake in indexing and I think it would be a mistake here. |
My issue is that Operating on a mixture of px and percent should actually be possible and neither be a panic nor convert to I also disagree that panicking on basic operators is a problem, but that's a separate discussion that I don't want to have here. I have had to deal with so many bugs in js caused by values being evaluated to So here's the possible solutions I see:
Personally, I'd prefer 1 or 3, 2 is fine but less ideal and 4 is unacceptable. There's technically a 5 that would be the |
@maccesch just to clarify a bit, when I say that number 4 is unacceptable. Your PR was completely fine based on the issue description and I don't want you to take this personally. You did a good job with the PR I just disagree with the overall api direction. |
Yep, regardless of the final choice I really appreciate you pulling this together so we have a concrete implementation to debate. Much easier here than to argue in the abstract. |
Then approach 3. seems like the way to go? That being said, I'm pretty sure that any operation with the Am I thinking about this incorrectly? |
Yes, if we eventually have a |
@IceSentry That's very nice of you say! I didn't take it personally at all and I agree with you. For sure I agree on the JS I like solution 3 the most anyway because in my limited understanding it's the closest to the Rust "spirit" of things - don't allow the programmer to do bad stuff in the first place. |
So in the context of this PR and the general consensus to go with option 3:
Are there any changes from this PR that it makes sense to merge or do we close this one? |
I think we close this down. |
lol my first PR to Bevy already went from good first issue to controversial to closed 🤣 |
It was a valuable contribution :D |
It helped us see a problem we didn't know we had 😄 |
Objective
Solution
I tried to "extrapolate" the
match
patterns from thef32
implementations. The principle I ended following is:I feel there's a high probability that this is not exactly what you had in mind. 😄
Let me know!