<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br>I would like to revoke my support for the removal of the C-style for-loop because of the following reasons:</div><div><br></div><div>Peformance</div><div>When doing the review appended below I have neglected to think about performance issues the replacement of C-style for-loops by for-in loops might have. This has not been part of the discussion either, so I am worried that it is not possible to replace C-style for-loops without losing performance or having to use while-loops which might be more verbose especially in the problematic cases with continue and break that have been discussed.</div><div><br></div><div>Style</div><div>When replacing C-style for-loops by while-loops I fear that bad styles will creep in like the usage of "defer" for the incrementation part of the loop which has been suggested too often in the discussion, even though it has been made already clear by others that "defer" is not appropriate here because of changed semantics in case of break or exceptions.</div><div><br></div><div>Therefore I have reconsidered my review and now vote strongly against removal of the C-style for-loop, although I would like to see it replaced by a more Swifty version as proposed as alternative in my review below.</div><div><br></div><div>-Thorsten&nbsp;</div><div><br>Anfang der weitergeleiteten E‑Mail:<br><br></div><blockquote type="cite"><div><b>Von:</b> "<a href="mailto:thorsten@portableinnovations.de">thorsten@portableinnovations.de</a>" &lt;<a href="mailto:thorsten@portableinnovations.de">thorsten@portableinnovations.de</a>&gt;<br><b>Datum:</b> 10. Dezember 2015 um 08:22:51 MEZ<br><b>An:</b> Swift Evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;<br><b>Betreff:</b> <b>[swift-evolution] Review: SE-0007 (Remove C-style for-loops with conditions and incrementers)</b><br><br></div></blockquote><blockquote type="cite"><div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div></div><div><br></div><div><span>1. Evaluation</span></div><div><span>Initially I was hesitant but now I&nbsp;support this change.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">The C-style for-loop is syntactic baggage (the semicolons do not separate its parts very well) and suffers from the problem that it is imperative, i.e. The loop variable is just that, a variable, and therefore will not work as expected when captured in closures that are executed later, e.g. in a GCD queue.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">There might be some corner cases where the C-style for-loop cannot be easily replaced with a for-loop or a while-loop in the presence of several continue statements, which is why I originally proposed to Swiftify the C-style for-loop instead of removing it, but I haven't seen a concrete one yet and I am optimistic that good solutions can be found even for these cases by refactorings e.g. extracting the loop body into a function and replacing continue with return. If someone has a concrete case for which that does not apply for some reasons I'd be interested to see that case and reconsider.</span></div><div><br><span>2. Significance</span></div><div><span>The C-style for-loop does not fit syntactically and its use is limited. In most cases the for-in loop is much better suited and more expressive and for the remaining few cases a while-loop can be used.&nbsp;</span></div><div><span></span><br>3. Direction of Swift<br><span>This proposal fits the philosophy of Swift with regards to readability and safety because the alternatives are more expressive and readable.</span><br><br>4. Comparisons<br>I have long experience with mostly Smalltalk, Haskell, Swift and Java, and from earlier times with C, C++, Python and Ruby. Furthermore I follow the development of many languages with modern constructs closely, e.g. Scala, Ceylon, Clojure and others and have a strong interest in programming language design.</div><div>Most of these languages, i.e. all except Swift, Java and of course C and C++, do not have a C-style for-loop. They typically do have more expressive loops similar to the for-in loop of Swift (or more powerful, e.g. Scala's for-expression which is similar to Haskells monadic do-notation).</div><div>Dylan has an iterating for-loop which improves on the C-style for-loop by introducing a new binding for the loop "variable" on each iteration, which might look like follows in a Swiftified syntax:</div><div><br></div><div><b>for</b> i = 0 <b>then</b> i + 1 <b>while</b> i &lt; limit { ... }</div><div><div><span style="background-color: rgba(255, 255, 255, 0);"><b>for</b>&nbsp;i = 0&nbsp;<b>then</b>&nbsp;i + 1&nbsp;<b>until</b>&nbsp;i == limit { ... }</span></div></div><div><br></div><div>which effectively introduces a let binding in the init clause scoped to the loop, an expression to replace the binding with for the next iteration and a while or until clause which is checked before each iteration.</div><div><br></div><div>I would propose this as an alternative to removing the C-style for-loop if a review makes a convincing case that an incremental loop is still needed.</div><div><span></span><br>5. Effort<br><span>I read the proposal carefully, read the discussion in the mailing list, checked two large Java codebases (large systems for logistics) for occurences of for-loops and did only find trivial ones. Furthermore I checked textbooks&nbsp;</span><span style="background-color: rgba(255, 255, 255, 0);">for their looping constructs</span>, e.g. "Concepts, techniques and models of computer programming" by van Roy and Haridi (highly recommended!), .</div><div><br></div></div></blockquote></body></html>