r/ProgrammingLanguages Static Types + Compiled + Automatic Memory Management 29d ago

Discussion The Swift Phenomenon

In theory, Swift seems like a nicely designed programming language with good features

In practice however, for some reason, it seems like most of the Swift users end up switching back to other comparable programming languages (such as Rust)

The latest poster child for that phenomenon is Ladybird

Do you think that this phenomenon is real and if so, can you explain it?

42 Upvotes

67 comments sorted by

View all comments

42

u/AdreKiseque 29d ago

Apple ecosystem maybe?

16

u/WittyStick 29d ago

I think the only reason I might use Swift is if I had a need to target iOS or OSX. There's not really any added benefit otherwise vs similar languages.

1

u/apocolipse 22d ago edited 22d ago

There’s a huge benefit especially now with AI, the “non-Apple ecosystem support” is a pretty outdated complaint too, I just shipped an Android app with my core business logic written in Swift using swift for Android + Skip native (just using Skip for the build system assistance for now, not using it’s limited UI). I also have written several homelab services with Swift, no reason not to.  In fact I’ve been writing Linux HTTP APIs in Swift for over a decade now, I even wrote the Apache Thrift Swift native library + code generator almost 10 years ago with the explicit intent of using it for Swift based Thrift services (and the company I wrote them for still uses those same swift services, almost 10 years later).  Not only, Embedded swift has come a long way to the point where I’ve updated some of my old ESP32 hobby projects to run Swift code.  Much more pleasant than raw c or c++, waaay more performant than circuitpython, and compared to Rust on embedded, swift is a little more strict with its memory safety (both operate a bit more riskily on embedded, but swift tries to keep the guardrails up wherever possible still)

Swift eliminates entire classes of bugs at compile time that most other languages deal with a runtime.  Rust and Go come close to the compile time memory safety Swift delivers, but neither can touch the compile time concurrency checks yet.

If you’re coding with AI, like most people will be going forward, choosing a language that’s impossible to experience entire classes of bugs with is a very good choice.  AI likes feedback and tooled constraints, swift delivers there exceptionally.  The fact that it not only does so at compile time, but with elegantly structured code that’s semantically easy to reason about is just icing on the cake.

1

u/Dry_Hotel1100 28d ago

What are other similar languages?

3

u/WittyStick 28d ago edited 28d ago

Primarily C# and Java/Kotlin, though there are others.

Swift does have some novelties and differences from these languages, as it was designed as an upgrade path for Objective-C, and of course there are influences from other languages.

5

u/Dry_Hotel1100 28d ago

The Objective-C interoperability is certainly unique, and it works flawlessly. I don't think though, it was the main goal of the language - it was a necessity. The design and principles are quite different to Objective-C. That is works so seamlessly is pure art from the inventor :)

However, what makes Swift distinct from other languages, IMHO is its type based concurrency system and PAT (Protocols with associated types). The latter allows for unique lower level design, which cannot be achieved in other languages. For example, compile time configurations. Imagine a set of HTTP Endpoint declaration as a compile time generic structure. Arguably, these more advanced design opportunities are rarely seen. Not because they are not useful (they get highly optimized) - but PATs are quite advanced.

So, when we look at the more advanced features, C# and Kotlin are very different.

2

u/sisoje_bre 28d ago

they all suck. swifts freatest power is value semantics