/ devsbedevin

Thoughts about Kotlin (+Brixo app is out)

So the Brixo Control Android app by DevsBeDevin is available on the Play Store.

This app has been a first for me: the first project I've written fully in Kotlin.

TL;DR

I'm in love Kotlin. No more do we need to wait for Google to integrate Java 8 and Java 9 features into the Android runtime.
Meaning powerful lambdas, higher order functions, functional programming, null safety and so many goodies out of the box. I didn't get to play with the DSL but I hear it's fun as well.

But there one feature that shines brighter than the others, and that is backward compatibility

BC

There are 2 aspects to good backward compatibility: the ability to support existing technologies and the ease of switching from said old tech to the new one.
Kotlin does these beautifully.

Since it runs on the same JVM, Kotlin supports all existing Java libraries with zero configuration. That's gotta be a deal maker in any developer's eyes, considering how huge the Java ecosystem is. So you get all of Kotlin's features without needing to pay in migration currency. Considering what happens in the Sift <-> ObjC world, Kotlin is miles ahead of the curve. You can even mix Kotlin and Java code in your existing project using very simple annotations. Oh - and ProGuard is working out of the box as well.

Kotlin syntax is arguably more readable and concise than Java. An experienced Java developer looking at a piece of Kotlin code should feel quite at home:

class TimerDialogFragment : TimeDurationPickerDialogFragment() {

    var listener: TimeDurationPickerDialog.OnDurationSetListener? = null

    override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
        val dialog = super.onCreateDialog(savedInstanceState ?: Bundle()) as TimeDurationPickerDialog

        with ( dialog.durationInput ){
            setDurationDisplayBackgroundColor( Color.parseColor("#EE4158"))
            setDisplayTextAppearance(R.style.DurationPickerHeader)
            setUnitTextAppearance(R.style.DurationPickerHeader)
            setButtonTextAppearance(R.style.DurationPickerButton)
        }
        return dialog
    }

    override fun getInitialDuration(): Long = (10 * 60 * 1000).toLong() 


    override fun setTimeUnits(): Int = TimeDurationPicker.MM_SS
    
    override fun onDurationSet(view: TimeDurationPicker, duration: Long) {
        listener?.onDurationSet(view, duration)
    }
}

The real world

The Brixo Connect app utilizes RxJava as well as RxAndroidBLE, on top of countless more smaller Java libraries. Every piece of the puzzle fits perfectly. Writing functional RX code in Kotlin seemed exceptionally natural.

Throughout the entire project Kotlin felt natural to the Android API and in no point I have felt the need to switch back to Java in order to "make something work".

Making the switch

I've recommend these 2 courses, by Udemy:
Kotlin for Android & Java Developers
Mastering Kotlin for Android Development

The future

Google has gained some notoriety in regards to adopting new technologies (hi Jack, bye Jack). So adopting Kotlin is still a gamble.

However - there are lots of reasons to be optimistic about Kotlin. Google seems to be very active in supporting the language and the new native toolchains are very exciting.

Final word

It took me about 3 days to feel comfortable with Kotlin enough to trust it with a whole project. And I don't plan on looking back.

Being able to generate JS code and maybe iOS in the future is just the icing on the cake. I 💗 Kotlin.