[swift-evolution] C-style For Loops
sean at fifthace.com
Sun Dec 6 15:04:10 CST 2015
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.
> 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
> swift-evolution mailing list
> swift-evolution at swift.org
More information about the swift-evolution