News for hackers. Stuff that matters.
Re:Apple’s Use of Swift in iOS 13 by gigatexal on Thursday September 26, 2019 @03:27PM (#21084545)
You don’t think the swiftisms they added like trying to get rid of conventional looping constructs is odd?
Re:Apple’s Use of Swift in iOS 13 by favorited on Thursday September 26, 2019 @04:20PM (#21085071)
There's nothing unconventional about for/in loops on Apple's platforms. Even in Objective-C, NSFastEnumeration has been the recommended default loop mechanism for a decade+ now.
Re:Apple’s Use of Swift in iOS 13 by matthewmacleod on Thursday September 26, 2019 @04:16PM (#21085045)
Absolutely not. These are among the best features; in any language that has modern control flow, I rarely if ever use old-fashioned loops.
Re:Apple’s Use of Swift in iOS 13 by ken on Thursday September 26, 2019 @06:07PM (#21086099)
What are "old-fashioned loops"? Does that mean C-style?

As an also Lisp programmer, I find Swift's limited (and fixed!) set of control flow constructs downright ancient. They added for-each loops, but that's it. We had more "modern control flow" in the 1980's.

Re:Apple’s Use of Swift in iOS 13 by kccqzy on Friday September 27, 2019 @12:05AM (#21088313)
Diversity in control flow constructs isn't necessarily a good thing. In imperative languages you see goto being discouraged and removed. In functional languages you see things like call-with-current-continuation discouraged.
Re:Apple’s Use of Swift in iOS 13 by ken on Friday September 27, 2019 @09:57AM (#21092026)
It is to me. The alternative is implementing them ad-hoc in every function. (Or perhaps waiting another few decades for Swift to add them to its compiler.) Having used many languages at different points on the power spectrum, I remain unconvinced that there's any advantage to omitting abstraction capabilities and forcing programmers to deal with it.

Besides, both of those examples are essentially non-local jumps, and I'm not sure I'd describe them as "modern".

In a sense, Swift already allows diversity in control flow constructs, via closures and the trailing closure syntax. It's just somewhat awkward, and not flexible enough to implement, say, most of Lisp's ITERATE library. That's packed full of exactly the kinds of control flow constructs that I have to write out by hand in Swift every day.

Re:Apple’s Use of Swift in iOS 13 by mnem on Thursday September 26, 2019 @03:44PM (#21084729)
Do you mean the c style for loops? The were removed in favour of iterator style loops (for foo in bar { ... }). Or are there some others I haven't noticed?
Re:Apple’s Use of Swift in iOS 13 by ShamelessC on Thursday September 26, 2019 @05:51PM (#21085967)
It's actually more curious that they didn't have iterator style loops from the beginning. It's a pretty standard feature in newer languages and even plenty of older languages are adding support for it.
Re:Apple’s Use of Swift in iOS 13 by NobodyNada on Thursday September 26, 2019 @05:58PM (#21086030)
Swift had iterator-style loops from the beginning. It also initially supported C-style "for (i = 0; i < j; i++)" loops, but they were removed very early on (because in practice, they're rarely used for anything except iteration, and iterator-style loops are much more readable and less error-prone).
Re:Apple’s Use of Swift in iOS 13 by jmnicolas on Friday September 27, 2019 @08:49AM (#21091310)
I never looked at Swift, but for example how do you wright 10 times "hello world" on the command line if you don't have for loops ?

You could do it with a while loop (if it exists in Swift) but I'm at a loss as to why you would remove a for loop from a programming language.

Re:Apple’s Use of Swift in iOS 13 by NobodyNada on Friday September 27, 2019 @12:42PM (#21093805)
Iterator-style loops are much clearer and more concise in almost all cases. In this case you can iterate over a range:

    for i in 0..<10 {
        print(i)
    }
Re:Apple’s Use of Swift in iOS 13 by oflannabhra on Thursday September 26, 2019 @03:37PM (#21084658)
I don't. I much prefer a chain-able functional approach to multiple mutating loops.
Re:Apple’s Use of Swift in iOS 13 by AJRF on Thursday September 26, 2019 @06:46PM (#21086417)
You can always pass in an iterator tracker via the following, much cleaner!;

  for (value, index) in arr.enumerated() { // Loop body }
Re:Apple’s Use of Swift in iOS 13 by ASalazarMX on Thursday September 26, 2019 @03:48PM (#21084764)
To be fair, no language is going to be perfect. I don't mind them, but I remember how odd enumerations and mappings felt at first in Python. IMO, overall, the pros of Swift vastly outnumber the cons, when the alternative is Objective C.
Re:Apple’s Use of Swift in iOS 13 by gameswithgo on Thursday September 26, 2019 @04:37PM (#21085256)
Thats kind of the thing to do in C# as well, and Java Streams, and in Rust the fastest way to do loops is not to do them but use iterators.