Kotlin vs Swift: Why Swift Might Become A Universal Language

kotlin vs swift

Swift and Kotlin are the same thing.

Or are they?

If you are like me, then you might have gotten frustrated by statements like this that software developers through around then disappear into the woods.

Who will do a proper Kotlin vs Swift comparison and save the day by answering this question? When you are considering building a mobile app for iOS or Android, proper research is really important before you settle on a development tool. So you need a proper Swift vs Kotlin comparison to be able to decide which one will do it for you.

After building a few Android apps in Kotlin, I decided it was time I built an iOS app in Swift too so that I can establish the difference between these languages.

And you know what I found out? Well, that’s the purpose of this Swift vs Kotlin comparison today.

In this article, we are going to look at a Kotlin vs Swift comparison in terms of their capabilities, performance, usage, etc… At the end of this article, I hope to help you understand the differences and similarities between Kotlin and Swift programming languages.

Understanding these two languages will enable you to choose which one is best for your project. Also, as much as I will try to keep this comparison strictly between Swift and Kotlin, I’ll find myself talking about Objective C and Java language quite often.

Why? Because it keeps me excited! If you want to compare Kotlin with Java, check out my other Kotlin vs Java developer productivity post.

Let’s get started.

Kotlin

Kotlin is a statically typed programming language developed by JetBrains, aimed at fixing some of the shortcomings of the Java language.

Even though it was developed a few years earlier, it only became popular after Google announced its official support in Android app development in 2017. Today it has become a very viable alternative to Java for Android programming.

But what really is it trying to fix in Java? We’ll found out in a moment.

Swift

Swift is a general purpose programming language developed by Apple in 2014 to improve on the Objective C programming language.

It is mainly used for software development for iOS, macOS, tvOS, watchOS and now zOS for IBM servers. Since its release, it quickly became popular among iOS app developers and is not the go to language for iOS mobile app development.

How is Swift any better than Objective C, while still being different from Kotlin?

Let’s find out. When comparing Swift vs Kotlin, we’ll look into usage, language syntax, developer productivity and the future of both languages. Before we go farther, let me underscore that even though both Swift and Kotlin might seem similar, they’re more similar to their predecessors than they are to each other.

If that makes sense.

Kotlin vs Swift: Usage

Let’s begin by comparing Kotlin vs Swift based on where they are used.

Kotlin, is mostly used for native Android app development. Even though the open source team is working on a Kotlin multi-platform project that will enable cross-platform mobile development, it’s still at an experimental phase.

Swift, on the other hand, is nowadays used to building for anything Apple. This includes developing applications for iOS, macOS, tvOS, watchOS and z/OS.

So, apart from mobile and desktop app development, Swift is being used for web development through the z/OS servers. While Kotlin might have the advantage of Android devices outnumbering iOS devices, Swift has the advantage of currently being used in more platforms than Kotlin.

Kotlin vs Swift: Developer Tools

If you want to know one thing developers get attached, it is their development tools.

Once a developer falls in love with say the Visual Studio IDE, they’ll bash everyone else on the forums who try to badmouth their favorite tool, Visual Studio. So, what options do Swift and Kotlin offer developers for development?

Kotlin is supported out of the box in the Android Studio IDE. However, Koltin development does not limit you to a particular IDE or operating system. Because you can write your Kotlin code in any IDE or OS like VS Code, Atom, Sublime Text, Windows, Linux & Mac, you won’t need to learn a new tool.

If you want to get started with Kotlin, here are the best Udemy Kotlin tutorials for learning Kotlin fast.

Swift development is only possible within the Xcode IDE. This means you are limited to only one development tool because only the Xcode IDE can compile Swift code. Besides, since Xcode, the Swift development IDE can only run on a Mac, you can only develop your iOS app on a Mac computer. Don’t let this put you off though, Xcode is a great IDE and provides you everything you need in one place.

So, while Kotlin gives you a lot of flexibility in choosing your favorite development environment, Swift limits you to a Mac. Now, that might be a good or bad thing depending on if you own a Mac.

Kotlin vs Swift: Language Structure

Here is where we’re going to find the Objective C and Java limitations that Swift and Kotlin address… that make them look similar.

Concision and brevity

One of the main problems with Objective C and Java is the amount of code you have to write to implement even simple functionalities.

This amount of code is drastically reduced in languages like Python. So, both Swift and Kotlin come in to fix this by copying code brevity from other programming languages. If you write your mobile app in either Swift or Kotlin you’ll drastically cut down on the amount of lines of code you’d otherwise have to write in Java or Objective C.

The concision and brevity in Swift and Kotlin is one of the features that make them well favored among devs.

Code Syntax

Another area where Swift comes close to Kotlin…

Or where Kotlin comes close to Swift… whatever! Hey it’s just English, I’m not saying one is busy copying the other one 🙁

The code itself. In fact, this is what led to articles like this comparing Swift vs Kotlin, trying to show that the code is almost as exact as it can get. Both Swift and Kotlin define classes, variables and even functions in very similar ways.

From a quick glance the code might actually look similar even though the underlying mode of operation or execution is completely different. So, while Swift & Kotlin code have some similarities, there are many other differences that I will not cover in this article…

Memory management

Have ever wondered why apps always feels snappier and smooth on an iOS device than on an Android device?

Why are Android apps always hungry for more memory and processing power while similar iOS apps outperform them on lower end iPhones? Well, it’s become both Kotlin and Swift approach memory management very differently.

Efficient memory management is key to an app running smoothly and not always crashing or buggy. Kotlin, just like Java, approaches memory management from the point of garbage collection.

Swift, on the other hand, goes for Automatic Reference Counting, ARC. Studies and benchmarks that have been done prove that ARC memory management model is more reliable and precise than garbage collection. This is why a Swift app will always outperform a Kotlin app.

Null safety

One of the most frustrating things when coding mobile apps is handling null variables.

Because mobile devices use the NULL to denote the presence or absence of a value, improper handling leads to a NullPointerException that makes your app to crash. This is especially a problem is both Java and Objective C.

Well, the long dark night is gone.

While both Swift and Kotlin variables are non nullable by default, they also offer excellent NULL type checking to ensure these errors are caught at compile time, and not at runtime. Null safety is a huge improvement in mobile app development, thanks to Swift and Kotlin.

Interoperability

While both Kotlin and Swift are easier languages to learn as compared to Java and Objective C, both require some time to master.

So, how easy is to transition from Objective C or Java to Swift or Kotlin? Code interoperability is another very important feature that makes both Kotlin and Swift popular. Kotlin code is 100% interoperable with Java. This means that you can call Java code from within Kotlin, while also being able to call Kotlin code from within Java.

So, Java and Kotlin classes can exist site by side in the same file and the app will still compile just fine.

Swift, as well, can coexist with Objective C code.

So if you write some of your app code in Objective C, you can still include Swift code within it. This means you can use Objective C libraries in your Swift code as well as implement some of your functionality in Objective C at the same time. Code interoperability is a key feature between Kotlin vs Swift.

Your Java or Objective C teams, therefore, can transition incrementally into Swift and Kotlin without pressure. Later on we’ll also look at how this impacts developer productivity.

Kotlin vs Swift: Developer Productivity

How does Kotlin vs Swift developer productivity compare?

Which language enables you to develop an app faster or quicker?

Well, let’s compare Swift vs Kotlin developer productivity, by looking at the time it takes to learn the language, the coding speed as well as the ease of app update and maintenance.

Which one takes a long time to learn…?

Because of the brevity of both Kotlin and Swift languages, they offer a rather steep learning curve.

While they might be easier to pick if you have a background in Java or Objective C, you’ll need to put more effort to pick both Swift and Kotlin if you are a complete beginner. So, from this aspect they’re pretty much the same.

However, compared to learning Objective C or Java from scratch, you’ll learn Swift and Kotlin faster and become productive quicker.

How about coding speed…?

Both Swift and Kotlin enable you to write less to implement the same feature in either Objective C or Java.

Because you end up writing less code, you are able to implement more features and finally complete your app in a shorter time. This high coding speed in Kotlin and Swift leads to high developer productivity which shortens a project’s time-to-market.

Is the final code maintainable…?

You might think that since both Swift and Kotlin code are brief and concise, they might be harder to read making it harder to understand the flow of app logic.

The couldn’t be further from the truth.

Both Swift vs Kotlin code are very readable and easy to understand. So it’s easier to read and weed out the bugs because you can easily identify them from the code. Besides, since the lines of code are fewer compared to the previous languages, catching bugs is easier because there is less ‘surface area’ for the bugs to hide.

Lastly, because the NullPointerException problem is handled in both languages, you’ll experience less app crashes and system failures. Spending less time fixing bugs and more time adding features make you a more productive developer.

Deploying an app that has less bugs means less code update and maintenance needs. So, either Swift or Kotlin will make you a very productive developer compared to Objective C and Java.

Kotlin vs Swift: Community Support

Let’s now compare Kotlin vs Swift community support.

Having a strong and active community behind a language is not only key to the growth of the language, but also makes it easy for developers to use. This is because you can always find learning resources as well as forums for asking questions.

A quick Google search for “kotlin tutorials” returns 5M results while the same for “swift tutorials” returns 132M results.

So, from these results alone, Swift has more learning resources than Kotlin. I also reviewed the best Swift tutorials on Udemy here. Kotlin language has the backing of both Google and JetBrains, while Swift has the backing of both Apple and IBM.

I can’t let you go before I show you some Stackoverflow.com stats.

While there are 31k questions tagged “kotlin” on Stackoverflow, there are over 250k questions tagged “swift” on Stackoveflow.com Swift has a way bigger and better community support that Kotlin… and I’ll explain why this is the case in the next point of comparison. So in terms of Kotlin vs Swift community support, Swift is way ahead with a more integrated and active community.

Kotlin vs Swift: Future

Lastly, what’s the future of Swift vs Kotlin languages?

Now, this is very important.

Who wants to waste their time learning and mastering a technology that has no future… or rather a questionable future? The Kotlin community is working on Kotlin multi-platform that will enable you to write code that runs on both iOS and Android.

That gives Kotlin hope for a broader future use apart from Android development. That’s also true for Swift because, apart from already being used in many more platforms, Swift is already being used in web development too.

Now, onto the most interesting part…

And this is why I think the Kotlin community is smaller.

Is the future clear? While Google embraced Kotlin as a first class Android programming language in 2017, I don’t think it was from a genuine standpoint. To me it looks like a way to fight back Oracle for suing them over their use of the Java APIs in the Android operating system.

Think about it, while Google is embracing Kotlin for Android, they are also developing the Fuschia mobile operating system that runs on Dart, their own programming language. Who knows… they might someday ditch Kotlin for Dart.

With this in mind, developers are treading carefully not to end up mastering a technology that might become obsolete overnight. Swift, on the other hand, had the full support and backing of Apple from its launch in 2014. Apple gave a clear signal that the way to go was Swift for iOS development.

So iOS and Mac developers confidently moved into Swift without any second thoughts and that’s why its community grew pretty fast. So, in my opinion, while Swift has a very promising and stable future… I can’t confidently say the same for Kotlin. Remember Kotlin never got mainstream until Google backed it up.

What if they pull out?

Well, that’s it with this Kotlin vs Swift comparison.

I hope you now understand the differences and similarities between these programming languages. Are you now ready to choose which one to use for you mobile app project?

Like I promised earlier, let’s finish this Swift vs Kotlin comparison by outlining 5 reasons why I think Swift might become a universal language.

5 reasons Swift might become a universal language

  1. The concise syntax and brevity of Swift has proved very dear to developers as is clear from the community behind Swift
  2. Swift code runs much faster than Kotlin. In fact, benchmarks put Swift performance close to good ol’ C++.
  3. With Swift for web development becoming a reality, it’s only a matter of time before web devs flood it with mvc frameworks that everyone can use.
  4. Apple is very firm in their support for Swift, so any developer learning Swift doesn’t have any second thoughts.
  5. SwiftKotlin lets you convert your Swift code and compile it as Kotlin code. Isn’t that the coolest thing? 

Conclusion

Both Swift and Kotlin programming languages are here to stay.

This is mainly because each one of them aimed, mainly, to solve a problem that the mother language had. Even though the original languages for both iOS and Android platforms were great, they could not evolve fast enough with the current mobile app development needs.

Swift and Kotlin saw this gap and did what they had to do.

Transitioning from Objective C to Swift or from Java to Kotlin might seem like an undesirable move for you right now… but ultimately it’s something you are gonna have to face.

Luckily, both Swift and Kotlin offer your seamless or incremental transition because of the code interoperability feature they both have. Even though I might not have been able to highlight all the similarities and differences in this Kotlin vs Swift comparison, I tried to mention the ones that stand out the most.

I hope that this Swift vs Kotlin comparison has helped you understand both languages better… and that now you are ready to choose either Kotlin or Swift for your mobile app. One thing that really impresses me about Swift is the attempt to bring it into web servers for web development. I’m really keen to see how this feature rolls out.

Have you developed an app in either Swift or Kotlin before? Please share your experience in the comments below.

Lerma Gray

Lerma is our expert in online education with over a decade of experience. Specializing in e-learning and e-courses. She has reviewed several online training courses and enjoys reviewing e-learning platforms for individuals and organizations.

Related Post

OnlineCourseing
Helping you Learn...
Online Courseing is a comprehensive platform dedicated to providing insightful and unbiased reviews of various online courses offered by platforms like Udemy, Coursera, and others. Our goal is to assist learners in making informed decisions about their educational pursuits.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram