Closed colejd closed 3 years ago
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?
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 |==|
is less convenient than typing ==
(I also find it a bit less readable). I personally would use a fork or earlier version if the old operators were deprecated, but I'm also not optimizing how I write code for reduced compile times.
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 /==/
too weird?
@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.
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.
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.
I think this is ready for another round of review (@ZevEisenberg @chrisballinger @jvisenti). To summarize:
/
instead of |
to make them easier 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.