Skip to content

[stdlib] Change C-style for loop to Swift-style for-in loop #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

[stdlib] Change C-style for loop to Swift-style for-in loop #889

wants to merge 1 commit into from

Conversation

johnlui
Copy link
Contributor

@johnlui johnlui commented Jan 6, 2016

All changes are in one commit now, and it has been fully tested with no "C-style for loop" compiler warnings. @moiseev #826

@johnlui
Copy link
Contributor Author

johnlui commented Jan 6, 2016

also #742

@moiseev
Copy link
Contributor

moiseev commented Jan 6, 2016

Thanks @johnlui 👍

@nadavrot , you wanted to postpone merging this in (#742 (comment)) are we good now?

@@ -120,7 +120,7 @@ public struct Character :
@warn_unused_result
static func _smallSize(value: UInt64) -> Int {
var mask: UInt64 = 0xFF
for var i = 0; i < 8; i += 1 {
for i in 0..<8 {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an official style guide regarding these loops?
I find it easier to read when it's in the style of for i in 0 ..< 8 (with that spacing)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s no official guide. I will say that the standard library should remain internally consistent, I don’t see any compelling reason to change what we’re doing with range operator spacing.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re: internal consistency, the C-style formatting is also spaced in the way I suggested (it's not var i=0; i<8; i+=1).

Comparing 0..<3 and 0 ..< 3, I find the latter significantly easier to process in every case.
The decision ultimately doesn't affect my life in any way, but being an open forum, I wanted to put my vote in for readability.

@moiseev
Copy link
Contributor

moiseev commented Jan 8, 2016

Nice catch, @hmhv!
@johnlui please fix the 2 instances of using continue to incremenent loop variable.
For the lack of better way of doing it, here are screenshots.
screen shot 2016-01-08 at 12 02 35 pm
screen shot 2016-01-08 at 12 03 43 pm

@moiseev moiseev changed the title Change C-style for loop to Swift-style for-in loop [stdlib] Change C-style for loop to Swift-style for-in loop Jan 8, 2016
@johnlui
Copy link
Contributor Author

johnlui commented Jan 9, 2016

@moiseev OK, I will make a new pull request~

@johnlui
Copy link
Contributor Author

johnlui commented Jan 9, 2016

There is a bug-fixed PR #923 , so this will be closed.

@johnlui johnlui closed this Jan 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants