by melling · 9y ago · 0 comments
https://h4labs.wordpress.com/2016/02/09/should-i-use-objecti...
The ++ operator was removed from Swift. Haskell uses ++ for concatenation. The case where ++ to add 1 is desirable occurs much less often than a variable declaration, which is better in Swift.
while (*d++ = *s++);
Or sort in Haskell: qsort [] = []
qsort (x:xs) = qsort (filter (< x) xs) ++ [x] ++ qsort (filter (>= x) xs) func strcpySwift(_ d:UnsafeMutablePointer<CChar>,
_ s:UnsafeMutablePointer<CChar>) {
for i in 0... {
d[i] = s[i]
if s[i] == 0 {
return
}
}
}
Haskell-style sort in Swift is pretty nice: func qsort<T:Comparable>(_ arr:[T]) -> [T] {
var xs = arr[...]
guard let x = xs.popFirst() else {
return []
}
return (qsort(xs.filter{$0 <= x})) + [x] +
(qsort(xs.filter{$0 > x}))
}Back to the one idiomatic C example. The few places where it’s terse does not make up for the many other places where it’s not. You also have memory management with malloc for additional code. If you compare nontrivial code, Swift is a more modern, safer, less verbose, etc way to develop iOS apps vs Objective C.