Just over a year ago, I was plunged into the world of Swift when I inherited a large iOS app. It was a daunting prospect - a new language, a new IDE, not to mention learning all the Cocoa APIs.
But something just felt natural when I picked up Swift. Up until that point I'd mostly used Python, and had been on the look out for a companion language for some time. Golang had been my original go to, when I needed something more performant. But it felt too dissimilar to Python to make transitioning back and forth a seamless process. The more I used Swift the more I felt like it was a natural fit.
Look at this simple example. First, in Python:
# Using type annotations, which were added in Python 3: def get_message(name: str) -> str: return f'hello {name}' print(get_message('bob'))
And in Swift:
func getMessage(_ name: String) -> String { return "hello \(name)" } print(getMessage("bob"))
There are clear similarities between the two. It extends beyond functions as well - classes also look alike. Swift feels like a strongly typed Python.
On a daily basis I might switch between Python and Swift a dozen times, developing an API in Python, and an iOS app in Swift. It doesn't get tiresome.
One nice thing about Python is being able to experiment with ideas in the interpretter.
Swift ships with a nice REPL, which serves a similar purpose. Just type swift
on the command line.
It's still early days, but work is happening on making Python code callable from within Swift.
A feature called 'dynamic member lookup' was added in Swift 4.2 to improve Swift's compatibility with dynamic languages like Python.
The main impetus for this was Tensorflow for Swift. Python has historically been a huge player in the data science / machine learning space. Rather than porting all of these Python libraries to Swift, it's nice to be able to call them directly from Swift.
While it's possible to call Swift code directly within Python (see this gist), it's less hassle to just use a subprocess, or via RPC.
Even though I'm hopeful for Swift's future, there are some risks involved.
The main one is people's perception of it as a language solely for Apple platforms. A lot of effort has gone into making it work on Linux, and providing editor support outside of Xcode. There are also some promising web frameworks, which help extend its usefulness outside of mobile development, such as Vapor.
However, just having a language which feels familiar to Python developers, and unlocks the world of iOS and Mac development, is already a big win.