Emoji-driven development in Swift
⚠️ In case you find this article now that it’s past the 1st of April: This whole article is an April Fools’ joke and is not intended to be taken seriously. You can find lots of real articles on the category page or by listening to the Swift by Sundell podcast.
We can all agree that emoji is the ultimate form of human communication. Emoji transcends language barriers, reduces verbosity in things like text messages, and can help set the mood in a tweet or email.
This week, let’s take a look at how emoji can not only be a powerful tool for text and tweets, but for Swift code as well 👍😀🚀.
Beyond ASCII 🚀
The biggest benefit of Swift over Objective-C, is that we are no longer limited to ASCII characters when it comes to defining our types and APIs. For example, let’s say we’re building an app about books. What better way to declare a type representing a book than using an actual book for its name?
struct 📖 {
let 📛: String
let 📅: Date
var 👍: Int
}
As you can see above, using emoji for property names as well also increases the readability of our code (it’s obvious that 👍 means "number of likes"). It’s all really awesome and has no downsides.
Migrating to emoji 🚢
Now that we’ve established that emoji provides not only the ultimate way to communicate, but to write code as well, let’s take a look at how easy it is to start migrating text-based (AKA legacy) code to this superior new form.
The good news is that we don’t need to rewrite all of our code to start practicing EMOJI-DRIVEN DEVELOPMENT. Using Swift’s awesome typealisas
feature, we can easily add an emoji layer on top of our legacy code.
Let’s say we have an InboxManager
that deals with Message
objects in an email app we’re building. To be able to start using emoji to reference those types, without having to modify them at all, we’ll simply use type aliases:
typealias 📫 = InboxManager
typealias 📄 = Message
Using the power of extensions, we can also quickly migrate our methods and properties to emoji:
extension 📫 {
static func 👍(_ 📃: 📄) {
markMessageAsFavorite(📃)
🔃()
}
static func 🚮(_ 📃: 📄) {
moveMessageToTrash(📃)
🔃()
}
static func 🔃() {
sync()
}
}
With the above tweaks in place, we can now start writing our inbox management code emoji-style 🎉! Here’s how easy it now is to handle a like button being tapped, which causes a message to be marked as a favorite:
let 👍 = 🆗()
👍.👆 = {
📫.👍(📃)
}
Wow, isn’t the above the most beautiful, expressive, readable, declarative, functional code you’ve ever seen? 😍
10 simple rules 👍
OK, like all fancy new ways of working, EMOJI-DRIVEN DEVELOPMENT needs a manifesto. This manifesto consists of 10 simple rules that are good to keep in mind when starting to migrate to an emoji-based code base:
- Always use emoji when possible
- Prioritize clarity by removing text
- Rockets are symbols too
- Interesting code is best code
- Long lines of text are hard to read
- Foster an emoji-driven culture in your team
- Occasionally use text, but only when needed
- Organize your code by emoji type (rockets first!)
- Listen to your inner emoji
- Spread the word!
Easy peasy! 👌
Conclusion
EMOJI-DRIVEN DEVELOPMENT is clearly the future of Swift. Over the next couple of months I’ll announce a new podcast, workshops, a book and a conference all dedicated to this new movement. Stay tuned! 😀