[swift-evolution] Revisiting 0004 etc. - Swift deprecations
xiaodi.wu at gmail.com
Sun Apr 3 03:19:47 CDT 2016
On Sat, Apr 2, 2016 at 6:45 PM, John Heerema via swift-evolution
<swift-evolution at 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
> 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
> 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.
> 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
> 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.
> though the compiler may optimize the stride into the loop structure, it
> 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
> superior in 100% of use cases. Even then, I would argue against removing
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.
More information about the swift-evolution