While I never got much into natural languages (beyond my native tounge, a halfway solid english, and some bits and pieces of french), I have always been fascinated by (some) programming languages – I even wrote books about some of them.
I (literally) grew up with BASIC and 6502/6510 ASSEMBLER – on the VC20 and the C64. Later on, learned to hate C and love 680x0 ASSEMBLER – on the AMIGA. During the 90s, I enjoyed PASCAL and MODULA II, and then found a preliminary home in Python.
The 2000s were largely affected by C++ (which I always found much more interesting than JAVA) until I got acquainted with Objective-C – which later rised to the 2nd place in my top list – shared with Vala, which I still have a sweet spot for, since it liberated me from having to use C.
As I grew older (and suddenly realized that my lifetime is actually limited, imagine my surprise…), I learned to embrace higher abstractions and being able to formulate algorithms clear and concise. While Python allowed me to do that, its reliance on runtime errors as opposed to compile-time always bugged me.
During the 2010s, I settled on using Python on the server, and Objective-C on the client – still dreaming about a language I could use for both.
Fast-forward to 2020.
I have been a vocal critic of Apple's new language, Swift, since its debut – for reasons which I'm not going to repeat. Three months have passed since I started learning Swift and I think it's time for a first preliminary report.
TLDR: I like it – a lot more than I have ever thought – and will from now on try to use it pretty much everywhere.
Before moving on with some details, let me also confess that I'm pretty glad having waited for so long. Judging from the outside, the road to Swift 5 was a very rocky ride. Were I to begin with an earlier version, I might have given up or wasted many hours following a language that was such a moving target – changing every year in more ways than I would have been willing to participate.
Swift is very expressive and rich in syntax, semantics, and idioms – and it has a tough learning curve. As someone who has written Objective-C for almost a decade now, let me tell you that whoever told you that Swift is more accessible than Objective-C is a downright lier. Objective-C is a very simple language, as it adds one (yes, just one) construct (and some decorators) on top of another simple language – C.
Once I was beyond my reluctance to look into it, I finally see the beauty. Swift has almost everything I have ever wanted in a programming language. Among many other features, it has
On top of that it has a REPL (Read-Eval-Print-Loop), which can't be praised enough – it is the #1 missing feature in most compiled languages – and syntax for building DSLs (Domain Specific Languages).
And: It is Open Source – which is the #1 feature that has always irritated me with Objective-C.
I hate repeating myself. I love generic solutions. Over the last decade, I created a number of reusable frameworks that powered all the apps I wrote. It has accumulated quite a bit of stuff, as you can see here (generated using David A Wheeler's SLOCCount):
SLOC Directory SLOC-by-Language (Sorted) 2110719 LTSupportCore objc=2063905,ansic=31423,java=5914,cs=3822,cpp=2772, python=2397,sh=486 106939 LTSupportDB objc=106108,sh=831 35669 LTSupportTracking objc=17443,ansic=12219,cpp=4922,java=902,sh=128, python=55 30331 LTSupportUI objc=30053,sh=278 27116 LTSupportDRM objc=27116 9499 LTSupportBluetooth objc=9365,python=134 6143 LTSupportAutomotive objc=6143 5141 LTSupportAudio objc=5141 4510 LTSupportVideo objc=4510 3324 LTSupportCommonControls objc=3324 679 LTSupportDBUI objc=679 340 LTSupportMidi objc=340 271 LTSupportDiagnostics objc=271
One of the things contributing to scare me before switching to Swift was that I may had to rewrite all that again. But it ain't necessarily so.
Being probably the company that has the largest Objective-C codebase in the world, Apple worked hard on interoperability. Calling Objective-C from Swift is a breeze – they'll even convert method names for you. Not much to complain here. Almost every Objective-C construct is visible to Swift.
Calling Swift from Objective-C is a tad bit harder. Apart from having to including (generated) extra headers, the whole plane of types with value semantics is more or less invisible to Objective-C. There are ways to bridge (AnyObject), but it's cumbersome and sometimes very for generic code (__SwiftValue__).
In a surprising move, Apple released Swift as an open source project. And although the struggle of combining a product oriented software release cycle with a community oriented evolution process is sometimes obvious (you can follow the tension if you read some of the evolution threads on the Swift forums), they manage it quite well.
What catched my attention in particular was the invention of Server-side Swift and the Swift Package Manager, since these two projects have the power to replace my use of Python forever.
My new set of swift-frameworks will be open source and also support UNIX-like platforms (to a certain degree, since Apple still has their crown jewels like UIKit and AppKit closed), hence finally I can use my reusable solutions both on the client and the server.
Unfortunately Google backed somewhat out of using Swift. For quite some time it looked like they would embrace it as another first-class language for their forthcoming Android successor. This would have been the icing on the cake, but let's see – Kotlin is pretty similar Swift, but not it.
I'm now familiar enough with Swift that I made the decision to go all-in, helping to improve the server-side ecosystem as I go. Speaking about which – I still miss a bunch of features, in particular first-class coroutines for asynchronous algorithms, a proper database abstraction, and a cross-platform logging solution. But what I enjoy the most is to be a part of a vibrant (language) community again. People are way more excited when it comes to Swift as they ever were with Objective-C. And this is great!