It’s that time of the year again. One of the major computing firms has put its weight behind yet another programming language and you are wondering why.
Kotlin – Google’s new Love
Meet Kotlin – Google’s new love . Its main development is run from a team of JetBrains developers based out of Russia. Kotlin version 1.0 was released on February 15, 2016 which is really recent. This is considered to be the first officially stable release of the language. Kotlin has since then been gaining support and is now, one of the official Development languages for Android.
This is what Google Developer Product Group had to say about Kotlin: “We believe Kotlin is an excellent fit for Android not only because it gives developers what they want, but also because it matches the spirit of Android.”
Kotlin was announced as an official Android development language at Google I/O 2017. It has became the third language fully supported for Android, in addition to Java and C++.
The first thing to remember is that the key phrase here: “one of the”. So it’s not as if someone is taking away your choice to code in Java or C++. In fact as you will see below – choice and flexibility has actually increased.
Android App Development with Kotlin ?
We asked our developers to look at Kotlin , talk around and discuss among peers and ask what folks make of Kotlin.
We actually found that those that have used the language didn’t find the learning curve steep at all.
And that Kotlin added some capabilities which Java didn’t have, saving them time and effort.
Some of these capabilities were:
- Null safety through nullable and non-nullable types, safe calls and safe casts
- Extension functions
- Lambda expressions or Higher order Functions
- Data classes
- Type Aliases
Kotlin works fully on Android Studio IDE and very importantly has full Java compatibility. This makes learning and getting used to it really easier and speeds up development. Any Java developer can get used to Kotlin within a matter of hours and you can even use both Kotlin and Java files in the same project.
Using Java libraries with Kotlin-based projects works flawlessly as well. The reverse is also true.
Kotlin for android app development – features
Null Safety: Null safety is an interesting aspect of Kotlin where references that can be null have different type , thus enforced only during compilation. We get Null Pointer Exception free code and no run-time overhead due to extra Option wrapper.
Extension Functions: Extension functions are a feature that was missing in Java. With Kotlin, you can add behaviour to a class without directly extending it or using a design pattern like Decorator.
Data Classes: Let’s face it. No one likes creating classes with only properties (and many of them repetitive), to hold data. It can be tedious and boring but needs to be done for most business apps. But in Kotlin, you can declare the class and all it’s properties in a single line of code.
As another example specifically for Android, Kotlin also allows you to call reference to view implicitly to an activity which reduces boilerplate code. For example the code:
TextView text = (TextView) findViewById(R.id.myTextView); text.setText("Hi Folks");
myTextView.setText("Hi Folks") showing the brevity it brings
Cons with Kotlin for Android
There aren’t many cons with Kotlin, especially due to its inter-operability with Java. The only ones that one can think of are maybe the larger file package size than one built purely on Java – because of it’s own standard library. But also, Kotlin is little slower on Android studio.
The other issue with Kotlin is that it’s developer community and help resources are somewhat lesser currently, although this will definitely increase in the future.
SO should you use Kotlin or Java for Android app development? Our thought is Java will be there for a long time to come but that Kotlin can be a good second language to master for android developers. From the user point of view both would be pretty much equivalent , but it may be time saving for developers to code in Kotlin once they get used to it.