DEV Community

Kotlin vs. Swift: Are Android and iOS moving towards creating a universal language?

ScienceSoft on August 22, 2017

Once Kotlin received Google’s support, the sheer excitement of Kotlin fans wasn’t the only reaction to follow. Those not familiar with Kotlin wer...
Collapse
 
tsikes profile image
tsikes

A few other points:

Both languages have a non-mobile aspect. Swift is also used for macOS development, and is available on Linux. IBM is promoting it for web server-side development. Kotlin was originally developed as a general purpose JVM language, and is also used for web server-side development.

Only Swift is compiled to native code. I realize there's a native Kotlin effort, but it's in its infancy at this point. Swift is highly competitive with C++ as far as runtime efficiency goes - and it should continue to improve.

Swift is reference counted instead of garbage collected. Kotlin is garbage collected. The practical result of this is that Swift doesn't suffer from GC latency, while Kotlin efficiently handles cycles in allocated objects. Apple (and I) both believe that GC latency is detrimental in desktop apps, games and any type of realtime programming.

I'm hopeful that both languages will continue to improve. It's unfortunate in my view that Google hasn't committed to Swift as its eventual preferred language for Android development. Swift versus Kotlin is another waste of developer mental bandwidth along the lines of Vulkan versus Metal versus Direct3D.

Collapse
 
dimpiax profile image
Dmytro Pylypenko

Kotlin is pathetic parody to Swift. Also Kotlin's syntax sugar is under doubt.

Related to article: Any in Kotlin is a base class?
Swift has Any datatype for func / protocol / enum etc. What Kotlin does have accordingly?

Collapse
 
lovis profile image
Lovis • Edited

Also Kotlin's syntax sugar is under doubt.

Who doubts what? Don't really understand what that's supposed to mean.

Related to article: Any in Kotlin is a base class?

Yes, Any is basically Object from Java

Swift has Any datatype for func / protocol / enum etc. What Kotlin does have accordingly?

Don't really get what you mean again, but if you want to know about the Kotlin type system, you can check this: natpryce.com/articles/000818.html
In short: Everything in Kotlin extends Any, also interfaces, enums and function types.

All in all it's worth noting that calling a language "pathetic parody" of another language is not constructive and does not get us anywhere. Actually, it bespeaks of a pretty childish attitude and most of the dev.to community prefers to have a civilized discussion instead of ranting.

In the end, some things are better in Swift and some are better in Kotlin. Many things are the same.

Collapse
 
aaronbond profile image
Aaron Bond

Kotlin came first dude. If anything swift is a pathetic copy of kotlin. :)

Collapse
 
dimpiax profile image
Dmytro Pylypenko

Wikipedia says this to you?
Also, decision about who came first is incorrect to statement about parody.

Aaron, adhere to ethics. "Dude" – keep it to yourself.

Thread Thread
 
aaronbond profile image
Aaron Bond

the definition of parody is to imitate in a humorous way, so which came first is pertinent to whether or not something can be a "pathetic parody" of something else.

and what am i supposed to keep to myself?

Thread Thread
 
nobody1707 profile image
Nobody1707

But in point of fact, Chris Lattner first started creating Swift in 2011, it simply wasn't released until 2014. They're similar solely because they have a similar set of influences. Neither is based on the other.

Collapse
 
technoplato profile image
Michael Lustig - halfjew22@gmail.com

Now now children. Everyone can have a seat at the table.

Collapse
 
Sloan, the sloth mascot
Comment deleted
Collapse
 
andy profile image
Andy Zhao (he/him)

Thanks for the article. It definitely enlightened my view on the two mobile languages. I think for competitive reasons they won't ever merge, but it's interesting that they're similar in so many ways.

Collapse
 
crummy profile image
Malcolm Crum

I think kotlin does support typealias as of 1.1.

Collapse
 
epabst profile image
Eric Pabst

True.

Collapse
 
mradzinski profile image
Matias Radzinski

"traits" is no longer a thing in Kotlin. It got replaced by "interface" like... two years ago? Honestly, I stopped reading at that.

blog.jetbrains.com/kotlin/2015/04/...

Collapse
 
bizzibody profile image
Ian bradbury

There will always be at least two types of reaction to articles like this.

[a] Horror that you promoted one or the other - or both
[b] Argument in the comments that you failed to mention x or y

Considering the difficulty of writing this type of comparison - I salute you.

Collapse
 
accesio profile image
Jimi Damon

Its kind of annoying that Google / Jetbrains had to invent yet another programming language when they could have gone with Groovy or Scala, two languages with very nice features. It just points to a bigger problem that Big Corporations don't accept grass roots based languages and keep dictating these silly technical schisms that force developers into one camp or another.

Hey Google and Apple, why not develop languages that are interoperable across language boundaries ? They have the money to actually build languages and environments that let a single developer develop apps for all major platforms...but instead they force you into unwavering allegiance to their dogma.

Collapse
 
arunprakash142 profile image
Arunprakash142

wow... this a feel good article if any of the business person are looking for assistance regarding there software development company. I found this site software development company.. young minds technology solutions is the company name for more details visit their site.

Collapse
 
swethamk profile image
SwethaMK

As a new bee to Kotlin, I see it as Swift being a readable version of Objective-C & Kotlin being a readable version of Swift!
Plus, its a relief to know there's light at the end of the tunnel for pure Java developers. Hopefully with further improvements in Kotlin, in due course of time, java developers need not be stuck to server side programming & can also easily flex their muscles in native mobile app development.

Collapse
 
badepaz profile image
badepaz

I enjoyed reading the article. When Kotlin was announced as being supported in Android Development, I was curious about the similarities to Swift as I'm an iOS / macOS developer. So this article helped give me a basis for comparison. Thanks.

A couple of notes.

First: (it should be noted that while Swift appeared in 2013, Kotlin originated back in 2011) - Swift was first revealed on June 2nd 2014, during the 2014 WWDC keynote.

Second: (In Swift these are blocks or closures, the terms from Objective-C.) - "Blocks" are from Objective-C and "Closures" are from Swift. While they both serve the same purpose (anonymous functions) they capture variables a little differently. So the TERM "Closures" doesn't come from Objective-C, it was started in Swift.

Collapse
 
acicartagena profile image
a c

nice write up. i noticed a few similarities when my coworker was presenting kotlin. (i use swift)

just a small correction though, you're missinv the '\' in the string interpolation. it should be "hi (name)" instead of "hi (name)"

Collapse
 
datadataservic1 profile image
Data Data Services

Comparing Kotlin with Swift. Can these languages trigger the appearance of a universal mobile development language for both Android and IOS. visit: compunneldigital.com/digital-trans...

Collapse
 
sahil_kwatra profile image
sahil kwatra

Great Article and well informed. I always love to read about technology. Here They Explain Well About Computer Se Mobile Me File Transfer Kaise Kare

Collapse
 
newshubfeed1 profile image
NewsHubFeed

Great Article and well informed I always love to read about technology and pets.Here They Explain Well About How often to change cat litter

Collapse
 
newshubfeed1 profile image
NewsHubFeed

Wikipedia says this to you?
Also, decision about who came first is incorrect to statement about parody.

Aaron, adhere to ethics. "Dude" – keep it to yourself.
Newshubfeed

Collapse
 
alliancetekinc profile image
AllianceTek

I agree with you that some points are very similar in both languages Kotlin and Swift. But both are used by developers according to their requirements. After getting Google support from 2017 Kotlin becomes more popular then Swift. Review link that how both are different in many things - bit.ly/2HztGRY

Collapse
 
kakashidinho profile image
Le Hoang Quyen

They already have an universal language called C.

Collapse
 
palle profile image
Palle • Edited

A big difference are value types, which are extremely important in Swift.

Collapse
 
lovis profile image
Lovis

yes. I would really love to have them for Kotlin, but the JVM does not (yet) support value types.

Collapse
 
epabst profile image
Eric Pabst

Swift value types are really a collection of language features. Here is a comparison of Swift's value types with Kotlin's features:

Enums representing choice

Swift:
enum VideoQuality {
case High
case Medium
case Low
}

Kotlin:
enum VideoQuality { High, Medium, Low }

Enums representing different things

Swift:
enum VideoMetadata {
case Program(channelId: String, programId: String)
case Ad(channelId: String, adId: String)
case Filler(channelId: String)
}

Kotlin:
sealed class VideoMetaData
data class Program(val channelId: String, val programId: String) : VideoMetaData()
data class Ad(val channelId: String, val adId: String) : VideoMetaData()
data class Filler(val channelId: String): VideoMetaData()

Tuples

Swift:
typealias Person = (name: String, age: Int)
let person = (name: "George", age: 30)
let (name, age) = person

Kotlin:
data class Person(val name: String, val age: Int)
val person = Person("George", 30)
val (name, age) = person

Note: I'm not aware that Kotlin supports passing a data class to a function in place of multiple named parameters. The workaround of course is to take the class as a parameter.

Struct

In Kotlin, a Swift struct would be ported to be a data class or basic class. However, it is NOT copied when passed around. However, there is an explicit copy method on Kotlin data classes to allow modifying on copy. (FWIW, I don't think I'd like an implied copy on assignment in Kotlin anyway.)

"Primitives"

Swift: Int, Bool, Double
Kotlin: Int, Boolean, Double

Class

They're basically the same in Kotlin as explained above.

Collapse
 
palle profile image
Palle • Edited

You could just call Swift code from Kotlin using the JNI :)

Thread Thread
 
lovis profile image
Lovis

Haha, "just" 😅

Collapse
 
craftopedia_craft_7b5774a profile image
Craftopedia Craft

Craftopedia is your premier online destination for unique DIY kits and craft supplies. Discover our selection of canvas painting sets, handmade bath soaps, card-making kits, and much more. Ideal for all ages, our products spark creativity and are perfect for gifting.

Collapse
 
biscottigelato profile image
biscottigelato

Kotlin nor Swift is the enemy. I just wanna kill myself just thinking about Javascript. Yet it is the preferred cross-platform development methodology of choice (React Native). Argh.

Collapse
 
justinctlam profile image
Justin Lam

Nice write up but where's the love for C#? Many of these concepts have been in C# for awhile.

Collapse
 
lovis profile image
Lovis

True.
C# had Type inference, extension functions and lambdas first, but they also didn't invent those concepts ;-)

The biggest issue though is that you don't nearly get the same programmer experience when you target iOS or Android with C#. The biggest plus for Kotlin and Swift are the interoperability with Java, respectively Obj-C.
Also, C# is getting older as well and - just like Java - has a lot of ceremony and needs a lot of boilerplate code to achieve the same results as modern languages.

Collapse
 
t4rzsan profile image
Jakob Christensen

Hi Lovis,

While I agree that C# is getting older it is certainly not getting outdated. Microsoft continuously improves the language, mostly by making it more functional. Just recently they added tuples and pattern matching.

I cannot speak for Kotlin, but I find it interesting that you think there is more boilerplate code in C# than in Swift. I work with both languages and I like them both. The main differences are in reference counting vs. garbage collection and in how the languages allocate memory on the heap vs. the stack. I actually find that the reference counting in Swift adds some extra boilerplate with the weak, unowned, and @escaping keywords.

On the other hand, Swift has some really cool syntax features when it comes to lambdas.

Compared to functional languages like F#, both Swift and C# add a lot of boilerplate stuff though.

By the way, you should try Visual Studio for Mac which gives you both macOS and iOS developing (as well as ASP.NET Core). In my hubmle opinion, XCode is seriously lacking when it comes to code editing and debugging :-)

Best regards,
Jakob

Thread Thread
 
lovis profile image
Lovis • Edited

Hey Jakob! :-)
You're right with the extra boilerplate for the ARC.
However, I'm on Kotlin, not on Swift, and Kotlin is Garbage collected.

My point with the boilerplate, though is that Kotlin and Swift are developed with Android/iOS in mind, and they will therefore probably always be more suited for that

Collapse
 
mathewr50343058 profile image
Mathew Richard

That was amazing reading it . I've also written some articles in my site kindly visit exporthub.co

Collapse
 
davidag9 profile image
Agyakwalf

I think dart is the unifying language for both....though it still needs a little more work

Collapse
 
kanhaiyakwatra profile image
Kanhaiya Kwatra

i love kotlin language
Usa news

Collapse
 
techpanga profile image
Manoj Chakraborty

Nice info.Kotlin need to be upgrade more

Naruto Senki Mod APK Unlocked All Character

Collapse
 
lorenzosjb profile image
Lorenzo Jiménez • Edited

Why do these companies do not use JavaScript? Ahh!! Because they cannot control the language.

Collapse
 
cagatayy profile image
cagatay-y

In the function and computed properties examples, backslashes before paranthesis are missing for string interpolation in Swift.

Collapse
 
lovis profile image
Lovis

also kotlin interfaces are not called "traits" anymore. like for two years now. 🙄

Collapse
 
newshubfeed1 profile image
NewsHubFeed

Swift is nice, but Kotlin is a lot prettier in my opinion. I am learning now Swift, and it's so similar. Nothing like the distance between Java and Objective-C
From Newshubfeed.com

Collapse
 
juanmendez profile image
Juan Mendez • Edited

Swift is nice, but Kotlin is a lot prettier in my opinion. I am learning now Swift, and it's so similar. Nothing like the distance between Java and Objective-C

Collapse
 
sandeepxtsworks profile image
Sandeep Saini

You have given very useful information about Kotlin and Swift language. It is interesting that they are similar in many ways. Tech Se Gyan

Collapse
 
kanhaiyakwatra profile image
Kanhaiya Kwatra

fonts are very useful to create a graphics, get a free fonts from the website