In pursuit to a more idiomatic Swift


(Adriano Ferreira) #1

Hi everyone!

While learning and in pursuit a to more idiomatic Swift, I put together a playground where I’ve been experimenting with some simple sorting techniques.

I’d appreciate any ideas on how to improve those algorithms into a more Swift-y form.

So, here is the repository <https://github.com/adrfer/Sort>.

Best,

— A


(Adriano Ferreira) #2

Hi everyone!

Jus wondering what is more idiomatic in Swift?

guard !array.isEmpty else {
    return false
}

or

if array.isEmpty {
    return false
}

What about when it comes to indentation style?

if array.isEmpty {
    return false
}

Or is there an exception of simple one-liners? Is it still 1TBS <https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS>?

if array.isEmpty { return false }

Both styles are present in Apple’s Swifts projects on GitHub.

Best,

— A

···

On Dec 21, 2015, at 11:01 PM, Adriano Ferreira via swift-users <swift-users@swift.org> wrote:

Hi everyone!

While learning and in pursuit a to more idiomatic Swift, I put together a playground where I’ve been experimenting with some simple sorting techniques.

I’d appreciate any ideas on how to improve those algorithms into a more Swift-y form.

So, here is the repository <https://github.com/adrfer/Sort>.

Best,

— A

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


(Erica Sadun) #3

Funny you should ask:

Migrating `if`s to `guard`s in Swift <http://ericasadun.com/2015/12/29/migrating-ifs-to-guards-in-swift/>
https://medium.com/swift-programming/why-swift-guard-should-be-avoided-484cfc2603c5
Another take on guard <http://ericasadun.com/2016/01/01/another-take-on-guard/>

···

On Jan 4, 2016, at 11:18 AM, Adriano Ferreira via swift-users <swift-users@swift.org> wrote:

Hi everyone!

Jus wondering what is more idiomatic in Swift?

guard !array.isEmpty else {
    return false
}

or

if array.isEmpty {
    return false
}

What about when it comes to indentation style?

if array.isEmpty {
    return false
}

Or is there an exception of simple one-liners? Is it still 1TBS <https://en.wikipedia.org/wiki/Indent_style#Variant:_1TBS>?

if array.isEmpty { return false }

Both styles are present in Apple’s Swifts projects on GitHub.

Best,

— A

On Dec 21, 2015, at 11:01 PM, Adriano Ferreira via swift-users <swift-users@swift.org <mailto:swift-users@swift.org>> wrote:

Hi everyone!

While learning and in pursuit a to more idiomatic Swift, I put together a playground where I’ve been experimenting with some simple sorting techniques.

I’d appreciate any ideas on how to improve those algorithms into a more Swift-y form.

So, here is the repository <https://github.com/adrfer/Sort>.

Best,

— A

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org <mailto:swift-users@swift.org>
https://lists.swift.org/mailman/listinfo/swift-users