I'm programming in it daily and its uglier and has more syntax then it should. Its very much like my experience with Transact-SQL, I'll use it and gain as much proficiency as possible, but I really don't like programming in it.
Anything that makes code beautiful works for me. Swift somehow can't be per_line_efficient and aesthetically pleasing to me.
let x = “Hello world”
var isDone = false
Filtering an array in one line is much nicer than a for loop:
let newList = anArray.filter(...)
No header files reduces code significantly.
I am using a lot of different languages so 'what I am used to' means lots of different stuff. Ruby has some of C beauty. Python does not. Haskell is probably most beautiful of them all. All individual and from my point of view of course.
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.
https://stackoverflow.com/questions/9558335/filter-an-nsarra...
Food food1 = [Food alloc]initWithName:@"samsar" andId:@"1"];
Food food2 = [Food alloc] initWithName:@"rusaramar" andId:@"2"];
NSSarray array = [NSArray arrayWithObjects:food1, food2, nil];
[array filterUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary bindings) {
return [evaluatedObject.foodName hasPrefix:searchBar.text];
}];