New module for Linux Session’s app
In the last entry I posted about the project I complained about not being able to properly setup Gradle for Kotlin. Soon after uploading that post though, I managed to fix it and I started working on another module for the project. Photo Booth is a thing I wanted to see on every single conference I attended. The basic premise is that users can take photos at the event which would then be approved by an administrator. After that they would be uploaded to a server and displayed as a common gallery for all users. I believe it to be quite an amazing tool for networking and getting people to actually use the application.
As you can see on Github I’ve decided to write this module in plain Kotlin to test the interop between Java and Kotlin. So far I found no problems so Google delivered :). The learning curve isn’t that steep and I think I’m already faster with Kotlin than I’ve ever been with Java. I’ve only implemented about half of the logic and views behind the module but I already see that the code volume will decrease by about 30-40% compared to Java. It is amazing how concise and elegant Kotlin is.
The best bits (so far)
The days of NullPointerExceptions are over! Kotlin claims to be a great step towards null-safety and it is. The only way to get an NPE is to actually scream at the compiler to give you one. Really, only nullable!!.member throws NPE if nullable is null. The idiomatic ways of dealing with optional values are really elegant and straightforward. In the three samples I will present how much boilerplate can be reduced using Kotlin when it comes to null-safety and casting:
When and other expressions
Java’s selective switch has been exchanged for something much better. When can be used with any type and with much more than simple value check. Let the code speak for itself though:
On top of that
try are expressions so they can be used as such:
The todo list
Except for the great stuff listed above I am really looking forward to using some other features of Kotlin language in some future modules I will write for the project. The stuff listed below is my current to-learn list of topics I have some knowledge of but want to know more.
– Anko – amazing library of shorthands and utility functions for Kotlin
– Anko’s DSL – Now it is possible to create an Android application without using xml’s. Anko’s layouts provide great functionality to declare views concisely and efficiently directly in Kotlin code. I really need to look more into it as it seems really unreasonably great.
– Type Aliases – I have started a new project at my job using Kotlin and I’m trying to develop an easy to use, understandable, concise system of creating proper, safe, modular MVP architecture in Kotlin using Type Aliases. The goal is to change
ParkingP. I still have some open questions and work ahead of me. But I really want to focus on it some more in the next week.
I am really grateful for Kotlin but I still have a lot to learn before I can say I’m fluent with it. I will keep you updated and I recommend you try it on your own. Until then, stay curious.