Skip to content
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

Use trailing closures for single closure args #307

Closed
a4sriniv opened this issue Jan 27, 2016 · 5 comments
Closed

Use trailing closures for single closure args #307

a4sriniv opened this issue Jan 27, 2016 · 5 comments
Assignees
Labels
Milestone

Comments

@a4sriniv
Copy link
Member

Preferred

reversed = names.sort { s1, s2 in return s1 > s2 }

Not Preferred

reversed = names.sort({ s1, s2 in return s1 > s2 })
@a4sriniv a4sriniv added the rule label Jan 27, 2016
@a4sriniv a4sriniv self-assigned this Jan 27, 2016
@a4sriniv a4sriniv added this to the Sprint 13 milestone Jan 27, 2016
a4sriniv added a commit that referenced this issue Jan 30, 2016
@agordeev
Copy link

agordeev commented May 12, 2016

How about allowing these statements within the rule:

reversedTopTen = names.sort({ s1, s2 in return s1 > s2 }).prefix(10)
firstName = names.sort({ s1, s2 in return s1 > s2 }).first

?

@AntiMoron
Copy link

AntiMoron commented May 13, 2016

maybe this one is better ?

reversed = names.sort { $0 > $1 }

@agordeev
Copy link

Huh? @AntiMoron how it's related to the topic? :)

@a4sriniv
Copy link
Member Author

a4sriniv commented Aug 9, 2016

Hey @andrew8712, we think its best to keep this rule as it is, it will enforce this as the preferred style:

reversedTopTen = names.sort { s1, s2 in return s1 > s2 }.prefix(10)
firstName = names.sort { s1, s2 in return s1 > s2 }.first

@agordeev
Copy link

But this style reduces readability, especially when the chain is long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants