[swift-evolution] C-style For Loops

ilya ilya.nikokoshev at gmail.com
Sun Dec 6 15:08:32 CST 2015


There are a couple of ways of solving this issue:

1 refactor to where loop first, then convert to Swift
2 leave a fixit in Xcode that will perform while loop conversion
On Mon, Dec 7, 2015 at 00:04 Sean Heber via swift-evolution <
swift-evolution at swift.org> wrote:

> This is the exact scenario that lead to my own code base having a few
> cases of C-style (all of which I've now trivially removed). Even so, I do
> not believe it is worth keeping it around for this reason.
>
> l8r
> Sean
>
> > On Dec 6, 2015, at 2:37 PM, Michel Fortin via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > There is actually one good reason I see in favor of keeping the C-style
> for loop, and only one: ease of porting existing code to Swift.
> >
> > If you are porting code from another language that uses C-style for
> loops, currently you can keep the loop as is while you translate all the
> syntactic differences everywhere. If Swift didn't had a C-style for loop,
> then you'd need to rethink the control flow at the same time you are
> converting everything else, increasing the risk of errors during what is
> already a delicate operation.
> >
> > C-style for loops are very common in code you can find everywhere
> because many languages have it, and therefore there is a lot of algorithms,
> sometime tricky algorithms you don't want to mess up, that rely on such
> loops. Even if you had the desire to convert all of them to for-in loops in
> your port, rewriting the control flow *at the same time* you are addressing
> all the other porting issues is much worse than doing it in a separate step
> *after* the crude port has been tested to work.
> >
> > In other words: you should avoid refactoring everything in one step. The
> C-style for loop enables that.
> >
> > --
> > Michel Fortin
> > michel.fortin at michelf.ca
> > https://michelf.ca
> >
> > _______________________________________________
> > swift-evolution mailing list
> > swift-evolution at swift.org
> > https://lists.swift.org/mailman/listinfo/swift-evolution
> _______________________________________________
> 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/20151206/dd03f446/attachment.html>


More information about the swift-evolution mailing list