One of the opinions is that it values expressiveness, and having multiple ways to do things that means you can choose a nice way to express each line, rather than always being forced to write it the same way.
This is a trade-off. To use `guard` as an example, sometimes it may be clearer to use a guard, and sometimes it may not. Swift has chosen to provide both options, at the cost of users needing to learn both.
I think it developed a negative reputation for the fact that the first few iterations did have a lot of breaking changes and added a lot of features. This made sense to me, the first version was somewhat of an MVP and it needed plenty of work still, but the language is relatively mature now and has stabilised significantly in recent years.
The compiler isn't generally that slow overall, but there are performance edge cases where complex type-checking can take far longer than other things. If you're having problems with speed, I'd recommend profiling your build, it's possible there are a handful of functions that are taking most of the build time.
There are at least two major problems with this kind of PL design approach: 1.) when you work on a large codebase from multiple contributors, all the possible combinations of the available syntax and standard library calls will eventually get used, making your brain frustrate quickly when reading code written by others, and 2.) when you interview for a new job, all the possible combinations of the available syntax and standard library calls will eventually be asked about by interviewers, making you look and feel like an incompetent programmer.
I have to agree with the OP - Swift seems to be an unreasonably bloated PL. Unless one plans to work only with Swift all the time, learning all there is to learn about Swift on the way, it might be easier to just use Rust or Go.
I wouldn't agree, I feel Swift has significantly more surface area than Rust.
But even syntax and standard libraries aside, I think that Rust is significantly more "explicit", "consistent" and "predictable" than Swift. I consider those to be very important qualities in a PL. Maybe that's why Rust was easier to learn and memorize than Swift (with the exception of the Rust borrow checker and lifetime annotations that indeed have to be well understood to be even usable).
But it might be just me.
Where I do think Swift has a lot of noise though is @attributes. There’s just so many attributes to learn, especially if you happen to do SwiftUI or ObjC interop. Though rust has the same issue , it’s just there’s no ubiquitous UI lib like SwiftUI. I imagine it would have the same if it did.
How does one do that? I hit this problem a lot. (I’ve since learned to use lots of explicit casts to make it less bad.)
OTHER_SWIFT_FLAGS = -Xfrontend -debug-time-expression-type-checking -Xfrontend -debug-time-function-bodies
There's also this great WWDC session on build parallelization:
More languages need a guard. It’s a really great control flow operator to flatten your code. Rust added `let else` last year that does the same and it does wonders to clean up code.
There are things I dislike about Swift , like lack of explicit namespace organization (rust mod or c++ namespace keywords, and the enum trick does not count) as well as the ability to drop extensions anywhere (which leads to a lot of stream of consciousness programming). However I don’t think I’d really consider it ugly.
What languages are you coming from and what else do you not like about Swift?
The SwiftUI integration doesn’t materially change the language much. It’s based on passing in blocks as parameters and has been a norm for obj-c as well (effectively how everyone does completion handlers).
But I think that’s why language beauty is in the eye of the beholder. To me, Swift allows flatter/cleaner code while defensively programming with lower branching and higher ergonomics. That’s beauty. That’s why guard is so nice. But I can see how it might be off putting if you’re coming from other PL paradigms.
I think a lot of it comes down to whether people want simple syntax vs simple code. C for example is simple syntax but rarely ever simple code , Swift and rust are more complex syntax but much simpler code.
Might just be what you're used to, but I find languages without named parameters annoying, particularly when I'm reading code I'm not my own. They do a lot to disambiguate and make reading unfamiliar code much smoother.
I recognize you prefer smaller languages but I’d like to make a case for guards usefulness.
Guard is great because it’s a combined early return and assignment. Imho if you have a language with optionals, it’s a required pattern to have, or you end up with lots of conditional unwraps and nested blocks, or lots of placeholder variables that you might accidentally use in your code later causing safety or memory access issues .
Take the following code
if let foo = Some(optional) {yourLogicHere} else {return}
That’s one level of nesting.
Swift is nice enough to elide the Some matching so you’d just have
if let foo = optional {yourLogicHere} else {return}
Still one level of nesting but a little cleaner.
Now if you have a language based around safety, like Rust or Swift, a lot of functions return optionals. So you’ll keep nesting code in your checks for safety
Now take a guard.
guard let foo = optional else { return }
yourLogicHere
That’s one level of unnesting removed , and that compounds.
Better yet, you can chain them
guard let foo = optional, let spam = foo.lookup() else {return}
The equivalent in C like languages would be
type foo; if (!getOptional(&foo) return;
Now either you early return in the case of the optional failing or you nest. Nesting gets repetitive and deep.
Or you unnest like I have and have that foo sticking around un-initialized, potentially causing issues of use later.
Guard simultaneously removes both conundrums and makes your code both neater and safer.
It might seem like a quality of life feature to some, to me however it's an essential feature of swift and one of the better ones.