[swift-evolution] [Review] Remove C-style for-loops with conditions and incrementers

Paul Cantrell cantrell at pobox.com
Wed Dec 9 11:07:09 CST 2015


Review of SE-0007

* What is your evaluation of the proposal?

This is a sensible change. I am in favor of it.


* Is the problem being addressed significant enough to warrant a change to Swift?

In isolation, the problem appears too small to warrant a change — just a little cruft in the language, an unnecessary but mostly harmless remnant of Swift’s ancestry. The C-style for loop is not a common source of programmer error, and is easy for the compiler to implement.

However, in aggregate, cruft like this leads to language bloat and stagnation. In a garden, a single weed is not a problem, but never weeding is a significant problem.

We have a feature that is:

1. not widely used,
2. easily replaced with other languages features where it is used, and
3. inconsistent with the language’s general aesthetic.

Observation, theory, and taste agree. If this isn’t a feature to remove for the health of the language, then what is? If we do not pull this weed, then what weed would we ever pull?


* Does this proposal fit well with the feel and direction of Swift?

Yes.

1. Swift tends to favor concise language constructs over boilerplate code for common patterns (e.g. didSet, lazy, optional unwrapping conveniences). This makes the C-style for out of place for the two common cases, counting and collection iteration, both of which already have more Swift-like alternatives.

2. The ++ and — operators are already slated for removal, which makes the C-style for much less compelling.

3. Swift tends to encourage immutability. It’s a minor detail, but the fact that the C-style for rules out immutability for the index variable is particularly compelling to me:

    for i in 0..<16   // i is immutable by default

    for let i = 0; i < 16; i++  // doesn't work

4. The few cases raised on the list where C-style for might still be preferable over other loop constructs all involve subtle interaction between the iterator clause (third part of the “for”) and break/continue/return. When I’ve seen this kind of code in the wild, at least in my own experience, it (1) usually is brittle and in need of rewriting, and (2) tends to appear only in low-level system libraries and graphics-related bit-twiddling, neither of which seem like Swift’s areas of focus. (Swift’s favoring of explicit scalar type conversion and precision safety already make it ill-suited to low-level bit twiddling.)


* If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?

Ruby does not have a C-style for loop. I’ve used Ruby extensively since 2007, and have not once felt that I wanted a C-style for.


* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?

An hour or two. I’ve followed the discussion on the mailing list. I did a programmatic search of all of my own Swift code; I’ve never used the C-style for in Swift.




> On Dec 7, 2015, at 2:44 PM, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Hello Swift community,
> 
> The review of "Remove C-style for-loops with conditions and incrementers” begins now and runs through Thursday, December 10th. The proposal is available here:
> 
> 	https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md <https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md>
> 
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> 
> 	https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> or, if you would like to keep your feedback private, directly to the review manager.
> 
> What goes into a review?
> 
> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> 
> 	* What is your evaluation of the proposal?
> 	* Is the problem being addressed significant enough to warrant a change to Swift?
> 	* Does this proposal fit well with the feel and direction of Swift?
> 	* If you have you used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> 	* How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> 
> More information about the Swift evolution process is available at
> 
> 	https://github.com/apple/swift-evolution/blob/master/process.md <https://github.com/apple/swift-evolution/blob/master/process.md>
> 
> 	Cheers,
> 	Doug Gregor
> 	Review Manager
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151209/d842a05e/attachment.html>


More information about the swift-evolution mailing list