Expressiveness in a programming language is incredibly important. Many of the systems Moby builds are intended to have long lifespans and therefore code maintainability is extremely important. More expressive code efficiently conveys the original code writer’s intent more clearly — making it easier for future developers to come up to speed quickly.
It is clear that the Apple engineers had expressiveness top-of-mind when they designed Swift. It borrows many aspects from languages like Ruby and Python, while at the same time “dealing” with its C past as best as possible. Once I learned the language, I was left with an insatiable desire to write the most expressive code possible in Xcode. My complacency with the impossibility of writing expressive objective-c code is gone and I’ve been seeking clever ways to bury the past as deep as possible.
In order to purge as much of the old way from our projects going forward, I’ve been systematically questioning all of the traditional techniques for even the most basic things. It’s almost too easy to just translate objective-c code into a Swift equivalent, because oftentimes you pass up an opportunity to do much better. A perfect example of this is the simple, but frequent task of introducing a delay between two pieces of code.
Here’s an example of a common technique for introducing a delay: