-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add custom operators as alternatives to overloaded operators #93
Conversation
It's a hassle, but it would be good to add these to the tests. Or maybe just convert the tests over to the new operators, since they all forward? |
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.
I love it! I'd like to see us take a step further and consider deprecation of the old operator overloads, because their continued usage will always slow down compile times and could lead people toward tech debt without them realizing.
@available(*, deprecated, renamed: "|==|")
@discardableResult public func == (lhs: NSLayoutXAxisAnchor, rhs: LayoutExpression<NSLayoutXAxisAnchor, CGFloat>) -> NSLayoutConstraint {
If we go down the deprecation route, we should do a semver minor version bump, and update the docs/tests to use the new syntax.
Also, in the spirit of the Swift Evolution process, I'd love to see some samples of the new operators in action, so we can see how it actually looks, rather than having to imagine it. If we go @chrisballinger's route, we'll be able to see it in the sample app. |
@ZevEisenberg should I just replace the overloaded operators with the new ones in the sample app, or do you think it would be better to provide some alternative examples? I guess the answer would really depend on if we want to deprecate the overloaded operators, though. |
Would love to get @jvisenti's opinion on all of this, too. |
Changing to custom operators is something that's been discussed for a long time. I think it's good they're finally implemented, even though I've had reservations in the past. I'm not so sure about deprecating the old operators though, because Anchorage has always been about convenience and typing |
This is kind of how I felt about it too. I think the tech debt isn't a significant issue if your compile times are reasonable. If you start getting warnings that your functions are taking a very long time to compile, the new operators provide you a way out (just put the operators you already wrote "in jail"). You're also right that it's a pain to type. If you have any ideas for a better syntax I'm all ears. Maybe brackets would be easier to type out than pipes (e.g. |
Ah, brackets aren't allowed in operator names. I guess the real goal is to reduce the amount of cognitive overhead it takes to type out the operators, and my thought was to reduce the need to alternate pressing/releasing the Shift key a lot. I tried typing out a few alternatives to find something that's less difficult. Is |
@ZevEisenberg The overloaded operators are internally leaning on the new operators. I'm hesitant to update the tests with the new operators, as we could run into a future situation where a regression is introduced for the overloaded operators and our tests wouldn't catch it. |
This reverts commit 8ecebd5. # Conflicts: # AnchorageTests/AnchorageTests.swift
On the topic of testing, I defer to the old adage, "the only code you need to test is code you want to work." Test both? Too much work to code-gen the tests for both operators? It's not like this is an unbounded problem. You're probably five minutes of find-and-replace away from doubling up the tests. |
Mark! ...Mark! ...Mark! ...Football!
I've updated the tests to cover overloads and custom operators independently. I was worried that making the overload invoke the custom operator would hurt runtime performance (however negligibly), so I wrote some performance tests as well. Turns out the custom operators are about 4% faster. |
Remove views after each test to balance their addition before each test
I think this is ready for another round of review (@ZevEisenberg @chrisballinger @jvisenti). To summarize:
|
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.
I agree with all of your thoughts here. I do think that |==|
visually looks better than /==/
but it's definitely harder to type.
It's just italic! 😂 I agree with everything here as well. Nice work, @colejd |
Although I'd usually save the version bump for a separate PR. Separation of concerns 😉 |
This PR aims to solve the issue of slow type-checking performance due to operator overloading (see #83).
To solve this, I've added new custom operators that provide the same functionality as the overloaded operators. Essentially, users can opt in by surrounding the overloaded operators in a "box of shame" (thanks, Zev):
==
(changed to|==|
/==/
)<=
(changed to|<=|
/<=/
)>=
(changed to|>=|
/>=/
)This has a few benefits:
Here's a build timing summary for an app that makes heavy use of Anchorage:
Here's the build timing summary after switching to this branch using my new operators:
Overall, the build time went from 4:55 to 3:22.