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
Web Applications with Kotlin ktor

Web Applications with Kotlin ktor

Functional Programming, Kotlin, Software Development, Web
Introduction Disclaimer: This ktor article was originally published in the Dzone Web Development Guide, which can be downloaded here. When Google made Kotlin an official language for Android a few months ago at Google I/O, the language gained much popularity in the Android world quickly. On the server side though, Kotlin is not as broadly adopted yet, and some people still seem to be cautious when backend services are involved. Other developers say that Kotlin is mature enough and we can safely use it for any server application in which Java could play a role otherwise. If you want to develop web apps with Kotlin, you can choose from various web frameworks like Spring MVC/WebFlux, Vert.x, Vaadin and basically everything available for the JVM. Besides the mentioned frameworks there's also…
Read More
Kotlin Function Literals with Receiver – Quick Introduction

Kotlin Function Literals with Receiver – Quick Introduction

Functional Programming, Kotlin, Software Development
Kotlin Function Literals with Receiver - The Foundation for DSLs and many Library Functions Today I want to give a quick introduction to Kotlin Function Literals with Receiver. This concept is what makes Kotlin great for designing Domain Specific Languages as we know it from Groovy for example. Also, Kotlin's standard library includes many functions which many of you have already used or at least seen probably: apply and with are the most prominent ones. (more…)
Read More