Why making Swift Programming Language so complicated to use?

Hi all

I've been a web developer for quite some time, and last year I start diving into this "Swift" and "SwiftUI" app development thing.

While I mainly focus on app development, there are some options on framework/language to choose: React, Flutter, Swift, Android.

I also have moderate experience on other language like Python, PHP, JS, Go etc etc.

Up to this moment and this version of Swift (v5), the development experiences of Swift is: Worst.

I can only see that Swift is making simple things complicated, and difficult to read.

For example, a simple ForEach loop:

In PHP:

foreach($list_of_items as $item){
    ...
}

But in Swift:

ForEach(0 .. <5){ item in
  ...
}

At the first glance, it is so weird to put item outside the ForEach loop, until we read further and know that item is a parameter. I don't even know what the in keyword is all about.

But if you are using format like PHP, you don't need another keyword in.

And this is how Swift write try...catch

do {
    try checkPassword("password")
    print("That password is good!")
} catch {
    print("You can't use that password.")
}

Why can't Swift just do this, just like other programming language (Python, PHP)?

try{
    ...
}catch{
    ...
}

We can save another keyword do

And do you know how to use Camera features in iOS app? The template code is long and there are a lot of settings before writing the code so I don't put it here.

And actually, there are some 3rd parties Camera libraries that do the same thing?! That simplify the setup process.

Why can we use Swift native camera function like this:

objCamera = new Camera(some_configs)
objCamera.takePicture()
objCamera.close()

This really make me walk away from Swift.

So, here is my little suggestion: I hope that the next version of Swift can make things less complicated, and easy to use.

I'm not talking about syntax sugar, but really, writing easy to understand program is actually the joy of development.

Thank you.

ForEach(0 .. <5){ item in
  ...
}

At the first glance, it is so weird to put item outside the ForEach loop, until we read further and know that item is a parameter. I don't even know what the in keyword is all about.

That's SwiftUI specific which uses the closure syntax.

The reason for ìn` comes as you know from closure syntax when passing parameter.

In fact, in is to replace the { } used to declare func, as in the following :

        let closure = { (item:Int) -> Int in
            print(item)
            return 2*item
        }

        print(closure(3))

If no return value to return, this can be written in more compact form

        let closure = { item  in
            print(item)
        }

For try, the do is not for try, it is associated to catching any error raised, from try of anything else.

You can use try without it (and without catch) :

if let data = try? NSData(contentsOfURL: URL, options   print("Data Loaded")
} else {
print("Unable to Load Data")
}

I found interesting analysis here: https://stackoverflow.com/questions/32390611/try-try-try-what-s-the-difference-and-when-to-use-each

So that's true that some Swift constructs are a bit complex and need time to master. But there is usually a very good reason behind (that the construct is the same in more general cases).

Note: there is another complex one: if let case…

Why making Swift Programming Language so complicated to use?
 
 
Q