[swift-evolution] [Pitch] Retiring `where` from for-in loops

L. Mihalkovic laurent.mihalkovic at gmail.com
Tue Jun 14 03:18:43 CDT 2016



Regards
(From mobile)

> On Jun 14, 2016, at 8:41 AM, Charlie Monroe <charlie at charliemonroe.net> wrote:
> 
>> I used to do low latency java for trading systems... the kind of coding where we would go out of our way to avoid ANY intraday gc activity (yes it can be done, even for parsing xml files). So we cared about a lot of things... But when you look at the numbers above on a 4_000_000 iterations loop and say the differential matters? I say you are probably using the wrong tools to write your code in the first place, and you should be using accelerate.
> 
> Yes, I say it does matter. Of course, 4 million iterations is a fictional example that rarely occurrs on its own, but gives you an idea that there's more going on behind the scenes other than pure iteration.
> 
> You're looking at it from a point where one app does one thing and the loop will have just a few iterations. Try to look at it from a point where the entire OS, all the processes and kernel  are written in Swift (might be distant future, but Swift is heading that way, isn't it?).
> 
> In such case if each for-loop takes a few extra instruction, then - again - yes, it matters. I know we're not talking about all for-loops, just those filtering the sequence - which seems not that common of a case - but my point is valid, that Swift should provide easily-reachable means to be a "good citizen". Removing it will lead developers to use .filter(_:) instead, in order to save lines of code and additional typing.
> 
> While many searches in open source code found a minimum usage of for-in-where, I think this is not due to it being confusing, but just not well known, otherwise it would be used a lot more. Most developers that have prior programming experience will only skim through the Language Guide itself, which doesn't mention that `where` can be used in for loops (!!!), or even while loops and there isn't a single example where it would be used.
> 
> Both
> https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/ControlFlow.html
> and the ePub download on https://swift.org/documentation/#the-swift-programming-language
> 
> Maybe I'm missing something, but the language guide only mentions `where` for the switch-case scenario. So the argument (which floated around here) that this is not being actively used is kind of moot since how could anyone be using it since it's not properly documented and no one who doesn't closely watch release notes can possibly know about this.

Non-argument... everything that has been removed was documented prior to its removal.

> 
> 
>> 
>> As for the '
>> 
>>> 
>>> I've previously noted that if/guard-continue come in really close speed-wise, which makes them candidates for a fix-it in case `where` is indeed removed.
>>> 
>>> My response here was solely to Jean-Daniel's note that he mustn't forget to include the lazy accessor, pointing out that even the lazy accessor is slower than using an inline check.
>>> 
>>> 
>>>> 
>>>> -- 
>>>> Brent Royal-Gordon
>>>> Architechies
>>>> 
>>> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160614/1c561287/attachment.html>


More information about the swift-evolution mailing list