From Java Builders to Kotlin DSLs

From Java Builders to Kotlin DSLs

Android, Java, Kotlin, Tutorial
From Java Builders to Kotlin DSLs Introduction DSLs - Domain Specific Languages - are an ever trending topic in Kotlin circles. They allow us to flex some of the most exciting language features while accomplishing more readable and maintainable solutions in our code. Today I'd like to show you how to implement a certain kind of DSL - we're going to be wrapping an existing Java Builder in Kotlin. No doubt you've come across the builder pattern in Java before, for example if you're an Android developer, you must've used an AlertDialog.Builder, an OkHttpClient.Builder, or a Retrofit.Builder at some point. Wrapping a builder like this is a good exercise in just pure DSL design. All you have to worry about is designing the API you provide with your wrapper, since…
Read More
Android KTX – Android development with Kotlin

Android KTX – Android development with Kotlin

Android, Kotlin, Software Development, Teaching, Tutorial
Introduction Android KTX is an open source library or set of functionalities designed to make the Android development with Kotlin even more pleasant. You can find its website here. The abbreviation KTX stands for Kotlin Extensions, so this library is basically a set of extension functions, extension properties and other top-level functions. In this article, we take a look at what's inside this library and how we can take advantage of it. This library's goal is not to add new features to the existing Android APIs, but rather make those APIs easier to use by leveraging the features of the Kotlin language. Structure of Android KTX A very important thing to note at the beginning is that Android KTX provides functionalities which would be added to many individual projects by…
Read More
Kotlin Tutorial – Quick Reference – Getting Started with Kotlin

Kotlin Tutorial – Quick Reference – Getting Started with Kotlin

Functional Programming, Kotlin, Software Development, Tutorial
Introduction Disclaimer: This reference has originally been published as a DZone Refcard. Kotlin has become one of the most popular JVM languages in the past few months. One special reason is that it experienced a lot of attention in the Android community after Google made Kotlin an official language for Android development. Kotlin is being developed by JetBrains, who are responsible for the most famous IDEs out there, most notably IntelliJ IDEA. Nevertheless, it's an open source language, which can be found on GitHub. The language is said to be very concise, safe in terms of error frequency, interoperable with Java and also offers many features that enable functional programming, writing type-safe DSLs and much more. Beside the JVM, Kotlin can compile for most Android versions, down to machine code…
Read More