C-style For Loops


(Erica Sadun) #1

Does Swift still needs C-style for loops with conditions and incrementers?

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

-- E


Joining Old Orphaned Posts to the Main Threads
(Chris Lattner) #2

I am certainly open to considering dropping the C-style for loop. IMO, it is a rarely used feature of Swift that doesn’t carry its weight. Many of the reasons to remove them align with the rationale for removing -- and ++.

-Chris

···

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.


(Douglas Gregor) #3

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

  - Doug

···

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.


(David Smith) #4

Every time I’ve used a C-style for loop in Swift it was because I forgot that .indices existed. If it’s removed, a fixme pointing that direction might be useful.

  David

···

On Dec 3, 2015, at 3:36 PM, Douglas Gregor <dgregor@apple.com> wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com <mailto:erica@ericasadun.com>> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

  - Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Keith Smiley) #5

For what it's worth we don't have a single C style for loop in the Lyft
codebase.

···

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

> On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:
>
> Does Swift still needs C-style for loops with conditions and incrementers?
>
> <Screen Shot 2015-12-03 at 4.30.15 PM.png>
>
> More Swift-like construction is already available with for-in-statements and stride.
> This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

  - Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Andy Matuschak) #6

Just checked; ditto Khan Academy.

···

On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> wrote:

For what it's worth we don't have a single C style for loop in the Lyft
codebase.

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

  - Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Eric Chamberlain) #7

We’ve developed a number of Swift apps for various clients over the past year and have not needed C style for loops either.

···

--
Eric Chamberlain, Lead Architect - iOS
ArcTouch - App Development Studio

Custom apps for world-class brands and the Fortune 500
arctouch.com/work | arctouch.com/blog

On Dec 3, 2015, at 3:46 PM, Andy Matuschak <andy@andymatuschak.org> wrote:

Just checked; ditto Khan Academy.

On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> wrote:

For what it's worth we don't have a single C style for loop in the Lyft
codebase.

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

  - Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Lily Ballard) #8

Every time I've tried to use a C-style for loop, I've ended up switching
to a while loop because my iteration variable ended up having the wrong
type (e.g. having an optional type when the value must be non-optional
for the body to execute). The Postmates codebase contains no instances
of C-style for loops in Swift.

-Kevin Ballard

···

On Thu, Dec 3, 2015, at 04:50 PM, Eric Chamberlain wrote:

We’ve developed a number of Swift apps for various clients over the
past year and have not needed C style for loops either.

--
Eric Chamberlain, Lead Architect - iOS ArcTouch - App
Development Studio

Custom apps for world-class brands and the Fortune 500
arctouch.com/work | arctouch.com/blog

On Dec 3, 2015, at 3:46 PM, Andy Matuschak >> <andy@andymatuschak.org> wrote:

Just checked; ditto Khan Academy.

On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> >>> wrote:

For what it's worth we don't have a single C style for loop in the
Lyft codebase.

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> >>>>> wrote:

Does Swift still needs C-style for loops with conditions and
incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-
statements and stride. This would naturally starve the most common
point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style
for loops. We have richer, better-structured looping and functional
algorithms. That said, one bit of data I’d like to see is how often
C-style for loops are actually used in Swift. It’s something a
quick crawl through Swift sources on GitHub could establish. If the
feature feels anachronistic and is rarely used, it’s a good
candidate for removal.

- Doug

_______________________________________________
swift-evolution mailing list swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_________________________________________________
swift-evolution mailing list swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Sean Heber) #9

I found a couple of cases of them in my codebase, but they were trivially transformed into “proper” Swift-style for loops that look better anyway. If it were a vote, I’d vote for eliminating C-style.

l8r
Sean

···

On Dec 3, 2015, at 6:52 PM, Kevin Ballard <kevin@sb.org> wrote:

Every time I've tried to use a C-style for loop, I've ended up switching to a while loop because my iteration variable ended up having the wrong type (e.g. having an optional type when the value must be non-optional for the body to execute). The Postmates codebase contains no instances of C-style for loops in Swift.

-Kevin Ballard

On Thu, Dec 3, 2015, at 04:50 PM, Eric Chamberlain wrote:

We’ve developed a number of Swift apps for various clients over the past year and have not needed C style for loops either.

--
Eric Chamberlain, Lead Architect - iOS
ArcTouch - App Development Studio

Custom apps for world-class brands and the Fortune 500
arctouch.com/work | arctouch.com/blog

On Dec 3, 2015, at 3:46 PM, Andy Matuschak <andy@andymatuschak.org> wrote:

Just checked; ditto Khan Academy.

On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> wrote:

For what it's worth we don't have a single C style for loop in the Lyft
codebase.

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

- Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(ChanMaxthon) #10

How about this C code when rewritten in Swift:

char *blk_xor(char *dst, const char *src, size_t len)
{
  const char *sp = src;
  for (char *dp = dst; sp - src < len; sp++, dp++)
    *dp ^= *sp;
  return dst;
}

···

Sent from my iPhone

On Dec 4, 2015, at 13:35, Sean Heber <sean@fifthace.com> wrote:

I found a couple of cases of them in my codebase, but they were trivially transformed into “proper” Swift-style for loops that look better anyway. If it were a vote, I’d vote for eliminating C-style.

l8r
Sean

On Dec 3, 2015, at 6:52 PM, Kevin Ballard <kevin@sb.org> wrote:

Every time I've tried to use a C-style for loop, I've ended up switching to a while loop because my iteration variable ended up having the wrong type (e.g. having an optional type when the value must be non-optional for the body to execute). The Postmates codebase contains no instances of C-style for loops in Swift.

-Kevin Ballard

On Thu, Dec 3, 2015, at 04:50 PM, Eric Chamberlain wrote:
We’ve developed a number of Swift apps for various clients over the past year and have not needed C style for loops either.

--
Eric Chamberlain, Lead Architect - iOS
ArcTouch - App Development Studio

Custom apps for world-class brands and the Fortune 500
arctouch.com/work | arctouch.com/blog

On Dec 3, 2015, at 3:46 PM, Andy Matuschak <andy@andymatuschak.org> wrote:

Just checked; ditto Khan Academy.

On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> wrote:

For what it's worth we don't have a single C style for loop in the Lyft
codebase.

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

- Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Lily Ballard) #11

A straight translation using UnsafePointer without a C-style for loop
would look like

func blk_xor(dst: UnsafeMutablePointer<CChar>, src:
UnsafePointer<CChar>, len: Int) -> UnsafeMutablePointer<CChar> {
    for i in 0..<len {
        dst[i] ^= src[i]
    }
    return dst
}

-Kevin Ballard

···

On Thu, Dec 3, 2015, at 09:47 PM, ChanMaxthon wrote:

How about this C code when rewritten in Swift:

char *blk_xor(char *dst, const char *src, size_t len)
{
  const char *sp = src;
  for (char *dp = dst; sp - src < len; sp++, dp++)
    *dp ^= *sp;
  return dst;
}

Sent from my iPhone

> On Dec 4, 2015, at 13:35, Sean Heber <sean@fifthace.com> wrote:
>
> I found a couple of cases of them in my codebase, but they were trivially transformed into “proper” Swift-style for loops that look better anyway. If it were a vote, I’d vote for eliminating C-style.
>
> l8r
> Sean
>
>
>> On Dec 3, 2015, at 6:52 PM, Kevin Ballard <kevin@sb.org> wrote:
>>
>> Every time I've tried to use a C-style for loop, I've ended up switching to a while loop because my iteration variable ended up having the wrong type (e.g. having an optional type when the value must be non-optional for the body to execute). The Postmates codebase contains no instances of C-style for loops in Swift.
>>
>> -Kevin Ballard
>>
>>> On Thu, Dec 3, 2015, at 04:50 PM, Eric Chamberlain wrote:
>>> We’ve developed a number of Swift apps for various clients over the past year and have not needed C style for loops either.
>>>
>>>
>>> --
>>> Eric Chamberlain, Lead Architect - iOS
>>> ArcTouch - App Development Studio
>>>
>>> Custom apps for world-class brands and the Fortune 500
>>> arctouch.com/work | arctouch.com/blog
>>>
>>>
>>>
>>>
>>>> On Dec 3, 2015, at 3:46 PM, Andy Matuschak <andy@andymatuschak.org> wrote:
>>>>
>>>> Just checked; ditto Khan Academy.
>>>>
>>>>> On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> wrote:
>>>>>
>>>>> For what it's worth we don't have a single C style for loop in the Lyft
>>>>> codebase.
>>>>>
>>>>> --
>>>>> Keith Smiley
>>>>>
>>>>>> On 12/03, Douglas Gregor wrote:
>>>>>>
>>>>>>> On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:
>>>>>>>
>>>>>>> Does Swift still needs C-style for loops with conditions and incrementers?
>>>>>>>
>>>>>>> <Screen Shot 2015-12-03 at 4.30.15 PM.png>
>>>>>>>
>>>>>>> More Swift-like construction is already available with for-in-statements and stride.
>>>>>>> This would naturally starve the most common point for -- and ++ operators as well.
>>>>>>
>>>>>> My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.
>>>>>>
>>>>>> - Doug
>>>>>
>>>>>> _______________________________________________
>>>>>> swift-evolution mailing list
>>>>>> swift-evolution@swift.org
>>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>>
>>>>> _______________________________________________
>>>>> swift-evolution mailing list
>>>>> swift-evolution@swift.org
>>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>>
>>>> _______________________________________________
>>>> swift-evolution mailing list
>>>> swift-evolution@swift.org
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>>
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution@swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-evolution
>>
>>
>> _______________________________________________
>> swift-evolution mailing list
>> swift-evolution@swift.org
>> https://lists.swift.org/mailman/listinfo/swift-evolution
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution@swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


(Joe Groff) #12

Looks like you're on the right track. Check out the Swift evolution process if you haven't already: https://swift.org/contributing/#participating-in-the-swift-evolution-process Next step would be to fork swift-evolution and make a pull request, I believe.

-Joe

···

On Dec 4, 2015, at 10:56 AM, Erica Sadun <erica@ericasadun.com> wrote:

I honestly have no idea where to go next with this. Here's my starting point: https://gist.github.com/erica/cf064a34f8891fb7a4a8

Advice welcome.

-- E, inexperienced at this stuff


(Erica Sadun) #13

I honestly have no idea where to go next with this. Here's my starting point: https://gist.github.com/erica/cf064a34f8891fb7a4a8

Advice welcome.

-- E, inexperienced at this stuff

···

On Dec 3, 2015, at 11:02 PM, Kevin Ballard <kevin@sb.org> wrote:

A straight translation using UnsafePointer without a C-style for loop
would look like

func blk_xor(dst: UnsafeMutablePointer<CChar>, src:
UnsafePointer<CChar>, len: Int) -> UnsafeMutablePointer<CChar> {
   for i in 0..<len {
       dst[i] ^= src[i]
   }
   return dst
}

-Kevin Ballard

On Thu, Dec 3, 2015, at 09:47 PM, ChanMaxthon wrote:

How about this C code when rewritten in Swift:

char *blk_xor(char *dst, const char *src, size_t len)
{
const char *sp = src;
for (char *dp = dst; sp - src < len; sp++, dp++)
   *dp ^= *sp;
return dst;
}

Sent from my iPhone

On Dec 4, 2015, at 13:35, Sean Heber <sean@fifthace.com> wrote:

I found a couple of cases of them in my codebase, but they were trivially transformed into “proper” Swift-style for loops that look better anyway. If it were a vote, I’d vote for eliminating C-style.

l8r
Sean

On Dec 3, 2015, at 6:52 PM, Kevin Ballard <kevin@sb.org> wrote:

Every time I've tried to use a C-style for loop, I've ended up switching to a while loop because my iteration variable ended up having the wrong type (e.g. having an optional type when the value must be non-optional for the body to execute). The Postmates codebase contains no instances of C-style for loops in Swift.

-Kevin Ballard

On Thu, Dec 3, 2015, at 04:50 PM, Eric Chamberlain wrote:
We’ve developed a number of Swift apps for various clients over the past year and have not needed C style for loops either.

--
Eric Chamberlain, Lead Architect - iOS
ArcTouch - App Development Studio

Custom apps for world-class brands and the Fortune 500
arctouch.com/work | arctouch.com/blog

On Dec 3, 2015, at 3:46 PM, Andy Matuschak <andy@andymatuschak.org> wrote:

Just checked; ditto Khan Academy.

On Dec 3, 2015, at 3:43 PM, Keith Smiley <keithbsmiley@gmail.com> wrote:

For what it's worth we don't have a single C style for loop in the Lyft
codebase.

--
Keith Smiley

On 12/03, Douglas Gregor wrote:

On Dec 3, 2015, at 3:32 PM, Erica Sadun <erica@ericasadun.com> wrote:

Does Swift still needs C-style for loops with conditions and incrementers?

<Screen Shot 2015-12-03 at 4.30.15 PM.png>

More Swift-like construction is already available with for-in-statements and stride.
This would naturally starve the most common point for -- and ++ operators as well.

My intuition *completely* agrees that Swift no longer needs C-style for loops. We have richer, better-structured looping and functional algorithms. That said, one bit of data I’d like to see is how often C-style for loops are actually used in Swift. It’s something a quick crawl through Swift sources on GitHub could establish. If the feature feels anachronistic and is rarely used, it’s a good candidate for removal.

- Doug

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution


(Douglas Gregor) #14

Just to close the loop on this… the review of Erica’s proposal is now scheduled for December 7-10, 2015, and is on the review schedule here:

  https://github.com/apple/swift-evolution/blob/master/schedule.md

The evolution process we’re following is described at

  https://github.com/apple/swift-evolution/blob/master/process.md

  - Doug

···

On Dec 4, 2015, at 11:07 AM, Joe Groff <jgroff@apple.com> wrote:

On Dec 4, 2015, at 10:56 AM, Erica Sadun <erica@ericasadun.com> wrote:

I honestly have no idea where to go next with this. Here's my starting point: https://gist.github.com/erica/cf064a34f8891fb7a4a8

Advice welcome.

-- E, inexperienced at this stuff

Looks like you're on the right track. Check out the Swift evolution process if you haven't already: https://swift.org/contributing/#participating-in-the-swift-evolution-process Next step would be to fork swift-evolution and make a pull request, I believe.


(Ray Fix) #15

Hi Erica,

One argument that I don’t see being made in your proposal is that the while statement provides an equivalent, more verbose form of C-style for loops.

var i = 0
while (i < 10) {
  print(i)
  i += 1
}

I understand that one of the major goals of Swift is to be a language great to learn about computing. Removing C-style loops doesn’t really diminished from this goal because the same thing can be taught with while.

Good luck,

Ray Fix


(Alex Chan) #16

Hi Erica,

I was a bit surprised that safety wasn't among the disadvantages of for
loops.

For loops make it easy to mess up the bounds of an array. You can miss
items at either end, or inadvertently read beyond the end. For example:

    for var i = 0; i <= bar.count; i++ {
        print("The \(i)th element in bar is \(bar[i]).")
}

There are similar mistakes where you can miss an element of an array at
either end. I'm struggling to imagine how you could make the same
mistakes with for-in loops.

Perhaps only a minor benefit, but I still think it adds to the case in
favour.

— Alex

PS If I try to run the snippet above in a Playground in Xcode 7.1.1, the
compiler error is fairly unhelpful:

···

Execution was interrupted, reason: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).