関連記事
-
What do I do as Business Analyst at AT?
Mar 20, 2019
Hi, my name is Hung Truong, an Android and Backend developer at Asian Tech. Having known Kotlin since its first Beta versions, I enjoy researching its possibilities and sharing knowledge to anyone interested in Kotlin by continuously adopting and promoting its potential.
This time I would like to share about how we use Kotlin at Asian Tech.
Content
Kotlin is an Object Oriented Language created by a Czech company called JetBrains. It is also a statically-typed language like Java, can be run on Java Virtual Machine and use LLVM to compile native code that supports multiple platforms. The very first question people usually make is why they invented this language. And what are its advantages over the others?
Interestingly JetBrains did not make Kotlin to sell, they made it to solve their own development problem instead. Most of their products were built with Java. That means a huge amount of maintenance work will be required over time. Java, like all of us know, is a powerful, stable but at some points using old-fashioned ways to write code.
It would be extremely cost intensive to rewrite all of their existing Java applications in any other languages. With that being said what they needed was a modern language that was compatible with Java, so that they could add new features to old applications using the new language without completely rewriting the applications from scratch. And that’s where Kotlin was born.
Kotlin is being adopted progressively by the industry. As of right now Android is still the main reason why they love Kotlin and come along with Kotlin. But we still have 30% of total Kotlin people who tend to be experienced programmers are using this language for Backend development. Let’s take a look at the spotlighted features that make people fall in love with Kotlin.
Null safety is the favorite feature for everyone who ever had a NullPointerException in Java. If you operate servers that run JVMs, there is no need to mention anymore about all the incidents involving NullPointerExceptions. Then you may ask yourself if there is any chance that none of those incidents would have happened. Lucky for you Kotlin is null safe by default! In Kotlin, from the variable declaration, you have to decide the variable whether nullable or not nullable and then the compilation will help you to avoid calling the null reference.
If you’ve ever watched any Intro to Kotlin talk, you’ve probably seen extension functions being told as one of the best features of this language. With Java, you might have to inherit a class or create some utility static method just to add a small piece of functionality to some classes. It works fine but not really convenient.
Kotlin provides the ability to extend a class with new functionality without having to inherit from the class or use any type of design pattern such as Decorator. It allows you to add behavior to a class without the need of getting to its source code since an extension function can be declared outside the scope of its class. And by doing so, they also improve the readability of your code.
While building any application, we often need to create classes in which the primary purpose is to hold data/state. These classes generally contain the same old boilerplate code in the form of `getters`, `setters`, `equals()`, `hashcode()` and `toString()` methods, and with these methods, it probably takes about 50 lines of code. You don’t need to write these code by yourself, any good IDE can generate all the boilerplate for you but the code is still there.
Kotlin has a better solution for you to create the classes to hold data/state. It’s called a Data Class. A Data Class is like a regular class but with some additional functionalities.
Java was born in the early 1990s and until now Java is still the most popular programming language for developers. Along with its long history, an abundant ecosystem with so many frameworks and libraries was created by Java. By using Java’s legacy and with the ability to be 100% interoperable with Java, we can use both languages in the same project without any problem.
Kotlin Multiplatform project was introduced since Kotlin version 1.2 and 1.3. From the beginning, working on all platforms is an ultimate goal for Kotlin and the more important goal is the ability to share code among platforms. Despite the fact that it is slowly picking up, cross-platform Kotlin is still very promising for developers to truly write once run anywhere, so that they can save effort for the more challenging stuff in the near future.
Have you ever created million of threads running at the same time in your code? You will be highly likely to get an OutOfMemoryException because of the expensive and heavy Threads.
Coroutines, introduced since Kotlin 1.1, are computer-program components that generalize subroutines for non-preemptive multitasking. You can think of a coroutine as a light-weight thread. Like threads, coroutines can run in parallel, wait for each other and communicate. The biggest difference is that coroutines are very cheap, almost free: we can create thousands of them, and pay very little in terms of performance. True threads, on the other hand, are expensive to start and keep around. A thousand threads can be a serious challenge for a modern machine.
Getting on with Kotlin from its first Beta version, we at Asian Tech are expanding Kotlin task force progressively.
By adopting Kotlin and applying it to real projects, what Kotlin benefited us are incredibly amazing in terms of Effort, Performance and Education Time.
・More concise and easier to learn compared with Java
・40% cut off lines of code
・More safety, less bugs
Since Google announced Kotlin as the first class support language on Android in Oct 2017, Kotlin has definitely been growing very fast. Provided all the improvements and benefits Kotlin brings to us over the old man Java including the conciseness, safety and productivity, there is no doubt that Kotlin will completely replace Java in developing Android applications in the very near future.
But people actually expect more to see how Kotlin will manage to seriously break into the communities outside of Android to become the new standard for Web, iOS and Backend. Given all the support by both JetBrains and Google, and the almost universal love that Kotlin receives in the industry, we are sure there are exciting times ahead for Kotlin ecosystem.
関連記事
Mar 20, 2019
Mar 20, 2019
Apr 26, 2019
Top Hashtags