It would be very interesting to see more examples dynamic loop conditions and dynamic loop increments using the Swifter for in loop with strides... without while :).
[[iOS messageWithData:ideas] broadcast] > On 3 Apr 2016, at 09:19, Xiaodi Wu via swift-evolution > <swift-evolution@swift.org> wrote: > > On Sat, Apr 2, 2016 at 6:45 PM, John Heerema via swift-evolution > <swift-evolution@swift.org> wrote: >> Yes, there are many cases in which I believe that Swift >> provides looping structures that are safer and easier to understand than >> the >> C-style For loop. I¹d even say most cases. But I work in the scientific and >> engineering domains, and can point to many instances of looping structures >> that >> are easily expressed with a C-style For loop, but are clumsy to implement >> without it. >> >> In the world of the natural sciences, there are any number >> of instances of loop increments that requires some kind of a calculation. >> There >> are any number of instances of dynamically calculated loop termination. >> >> Swift¹s stride has some nice features for simple increments, >> but also has some important limitations. Among them, it involves the two >> step >> process of first creating an enumerable set, and then iterating over it. >> In the >> natural sciences, it is not uncommon for complex loop increments to be >> used in >> loops that are executed millions of times. >> >> Conceptually, creating an enumerable set, and then iterating over it, >> reeks of the arrogance of assuming that computing resources are unlimited. >> Even >> though the compiler may optimize the stride into the loop structure, it >> feels >> like unnecessarily creating a gigantic enumerable set. >> >> Whether we like it or not, the enduring popularity of the >> C-style For loop comes from it¹s flexibility. Swift doesn¹t have a better >> alternative that also provides the same flexibility. So don¹t take it >> away. If >> you don¹t like it (I don¹t always either), think of something that is >> clearly >> superior in 100% of use cases. Even then, I would argue against removing >> it. > > FWIW, as an anecdote, I've been working on a side project in the > natural sciences using Swift and I haven't missed the C-style for;; > loop much. It seemed a little irksome at first to refactor, but that > was about it. Looking around at other languages, I'm also not seeing > evidence that working in the natural sciences domain > disproportionately requires these loops. For instance, Python (which > has significant uptake in my corner of the natural sciences world) and > Julia (the up-and-coming technical computing language) both lack > C-style for;; syntax and the ++ and -- operators, which doesn't seem > to have dampened the enthusiasm of my colleagues for those languages. > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution _______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution