-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Feedback #1
Comments
Thanks for sharing this library with the community, @sindresorhus. I wanted to share some feedback that I hope might be helpful / informative:
I think percentages can be a helpful abstraction in some circumstances, but I've yet to see any implementation that was complete, correct, and widely supported (the closest I've seen is in CSS, and even still there are some inconsistencies in when percentages are a valid unit). Unless this were part of the Swift standard library, I think adoption of this type would do more harm than good compared to using
Percentages are a particular kind of Rational numbers, where the denominator is equal to Currently, (50%) == (50%) // true (Equality)
(5%) < (50%) // true (Comparison)
(50%) + (50%) // 100% (Addition)
(50%) - (50%) // 0% (Subtraction)
-(50%) // -50% (Negation) However, it has incorrect implementations for Multiplication and Division: (50%) * (50%) // 2500% (should be 25%)
(50%) / (50%) // 1% (should be 100%) As far as how this would be received on the Swift forums, I'd direct you to previous threads proposing formal mathematical types, like Some additional feedback:
|
Hey there, @mattt I have little understanding of the subject but just out of the curiosity would like to ask your opinion on whether SwiftUI's Angle is a an abstraction similar to Percent? If so, we may see it adopted in the future versions of the framework sooner rather than later. I think having Percent would be very useful in a UI framework. |
@shengchalover That’s a great question. I think angles are different from percentages in several important ways:
For these reasons, I think it makes sense to have an Angle type, whereas it’s be difficult to make the case for a Percentage type. |
@mattt thanks for an in-depth answer! |
I like this idea, I'm using something similar to use
Maybe not as fancy as your
I can do something like:
wdyt? |
Thanks for this valuable feedback @mattt 🙌
|
One problem I'm having is that because
Any ideas? |
I assume you mean that this should work? let float: Float = 5%
No strong opinion on this, and not sure why it matters.
Shouldn't it conform to |
Is this a good idea? Any downsides with such a type? Would it make sense to propose adding this kind of type to Swift itself?
The text was updated successfully, but these errors were encountered: