[swift-evolution] Reconsider ++ and -- operators removal and prevent other well-known operators from change
swift-evolution at haravikk.me
Sat Jan 30 17:00:50 CST 2016
-1 from me.
I’m in favour of the removal for several reasons:
In many cases I’ve seen these operators use, the number is really used as an index type so should be encouraged to use the advance(), predecessor() and successor() methods for clarity.
I’ve seen numerous cases of tricky to diagnose bugs arising from foo++ and foo— being used in function calls and conditionals where a developer has misunderstood what value will actually be tested.
I’ve likewise seen ++foo and —foo misused in conditionals, particularly when foo is also present in the same conditional (or a function call) and a developer has misunderstood what value each instance of foo will result in. Plus it can easy to misread and result in some really hard to parse code when it comes to maintenance.
I think it makes sense for all assignment operators to include an equals and follow the same basic format. While lots of other languages may have these prefix and suffix operators, I like the idea of trying to keep operators to a useful minimum as standard.
It’s fairly easy to just add them yourself if you really can’t part with them.
Of course I’ve seen them used reasonably, but that’s mostly in things like loops where Swift provides a lot of good alternatives, plus the aforementioned index protocol. The rest of the time they’re often (in my experience) misused to create shorter, but not necessarily neater code, and can lead to a lot of silly, subtle errors.
That said I’m not hugely bothered either way (if they’re left in then I can just continue to not use them), but I think the reasoning for cutting them is sound.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution