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

David Waite david at alkaline-solutions.com
Thu Dec 10 18:27:54 CST 2015

Review of SE-0007

* What is your evaluation of the proposal?

I can understand how this change is controversial - however, I’m in favor of it.

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

Many examples have been given on the list of for loops that look more complex or involve additional nesting once C-style for loops are eliminated. However, I couldn’t help thinking many of these examples are greatly complex in themselves - that using a functional syntax (even if it makes the line longer or has the sequence building moved to another function) serves to make the code intrinsically more readable and maintainable.

For example, 

	for i in (0..<things.length).reverse() { … } is longer/more verbose, but is also very clear in purpose

For someone coming from C, for loop support may help them port their code quicker. However, for someone without C experience, the syntax and rules are different than the rest of the language (for instance, the for loop is the only construct which requires a semicolon for expression).

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


With ++ and -- operators slated for removal, the main motivator for having for loop support (ease of porting C-dialect code) is greatly reduced.

There is a push to use functional concepts in Swift (avoiding terms like Monoids and Monads since the theory isn’t needed for usage). Every for loop I’ve ever seen is non-functional, and the availability of the feature pushes people toward imperative thinking and coding.

** Additional feedback on evaluation

I *wish* there was greater consistency with blocks and closures, so that for - in … {…} wasn’t required in addition to .forEach {…}.

Some of the concepts given seem like they may warrant language use guidance (such as in TSPL book):

	for i in 0..<things.length { … } 

should perhaps instead be 

	for i in things.indices { … }

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

The main language I’ve used without for loops is ruby. I honestly didn’t realize they were missing until another review stated so - once I moved away from using them, I’ve never been motivated to go back.

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

I’ve followed the mailing list discussion and looked at my own code.

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

More information about the swift-evolution mailing list