The Expressive Nature of Swift

Guess that didn’t last long.

There’s a conversation happening in the iOS community at the moment, static vs. dynamic programming. On one side we have many people who have been writing Objective-C for over 20 years (wow!) saying that the dynamism of Objective-C is the reason why it is an amazing language, and has succeeded. The argument is predicated on the fact that those nay-saying it don’t understand the power of dynamism, and how it’s empowered programmers. On the other end you have many people saying that static languages are the way forward, and that a whole class of errors is avoided, and that we should look at all the bugs prevented by having a good type system!

This back and forth ignores that Chris Lattner, the creator of Swift, has himself stated that Swift is a hybrid, not explicitly static or dynamic. His explanation is very interesting, because it takes the argument from being black vs. white and turns it into many gray shades. Other languages have explored these concepts before, with ideas like gradual typing, which was born out of the idea of grafting a type system onto dynamic languages, not making static languages more expressive.

But what exactly is expressiveness? As this StackOverflow post explains (always cite your StackOverflow posts kids):

‘Expressive’ means that it’s easy to write code that’s easy to understand, both for the compiler and for a human reader.
Two factors that make for expressiveness:
• Intuitively readable constructs
• Lack of boilerplate code

Peter Norvig has a great talk on design patterns in programming languages. One slide stuck out to me as I was reading it recently.

Let’s break that down:

  1. There are fewer design patterns in expressive languages, because the type system does not prevent programmers from trying to express a concept.
  2. Dynamic languages by their very nature of a weak type system have less issue being expressive.
  3. This does not rule out static languages from being expressive!

The lack of expressiveness of static languages is dogma attached from other static languages that have existed before. I’d argue that Go is as expressive as Python, and Swift, even in its incomplete state, is nearly as expressive as many dynamic languages. You can recreate the advantages Objective-C offers through its dynamic nature by using different expressive techniques, like protocols and generics, in a statically typed language.


One more thing: Many arguments imply that Apple hasn’t thought about writing apps, that they built a static language, and forgot to take into account. Care to tell me which company writes apps on the most iPhones in the world? That’s right, Apple. I don’t think they’re stupid enough to create a language which they believe is objectively worse for writing apps.

Regardless of how this whole static vs. dynamic “conversation” turns out, one thing’s for certain, I’m #TeamSwift.