Find me on Medium

Software Development
Find me on Medium It has been a while since I posted on this blog. There are multiple reasons for this but mainly I just didn't have the time and motivation to continue blogging here. I have to be honest: The ROI was never really worth the effort, unfortunately. I am still super happy about the things I learned along the way and I'm happy to say that over 500k people visited my blog since I started it. I don't plan to kill it either, although I sometimes considered it as I don't like the fact that some articles are outdated and would actually need a rework. If you read articles on this blog, be aware that they have been written many years ago and may not be 100% accurate…
Read More
Serverless Kotlin with OpenFaaS

Serverless Kotlin with OpenFaaS

Cloud, Kotlin, Serverless, Tutorial
Serverless Kotlin on OpenFaaS With this article, my goal is to demonstrate how Serverless Kotlin can look like by introducing you to one of the coolest Serverless platforms: OpenFaaS. OpenFaaS is an open-source, community-owned project that you may use to run your functions and microservices on any public or private cloud. You can run your Docker image on OpenFaaS, which runs and scales it for you. As a result, you are free to choose any programming language as long as it can be packaged into a Docker image. Throughout this post, we want to learn about the concepts behind Serverless and Function as a Service (FaaS), and how we can deploy Serverless Kotlin functions to OpenFaaS. Serverless and Function as a Service Serverless Computing With Serverless Computing, we describe a…
Read More
Server as a function with Kotlin – http4k

Server as a function with Kotlin – http4k

Functional Programming, Java, Kotlin, Software Development, Tutorial, Web
Server as a function with Kotlin - http4k Have you ever heard about the concept of "Server as a Function"? The idea is that we write our server application based on just ordinary functions, which is based on a concept outlined in the paper Your Server as a Function written and published by Twitter/Marius Eriksen. In the Kotlin world, the most prominent implementation of this concept is http4k, which the maintainers describe as an "HTTP toolset written in Kotlin with a focus on creating simple, testable APIs". The best part about it is that http4k applications are just Kotlin functions that we can test straightforwardly. Take a look at this first example: First http4k server example val app: HttpHandler = { request: Request -> Response(OK).body(request.body) } val server = app.asServer(SunHttp(8000)).start()…
Read More
Default Map in Kotlin

Default Map in Kotlin

Functional Programming, Kotlin, Software Development, Teaching, Tutorial
Does Kotlin have a default Map? Have you ever used a default map or default dict before? If you know Python a bit, you probably saw its defaultdict in action at some point. Kotlin also comes with a similar tool which I want to demonstrate in this little article. You can find the Python defaultdict documentation and some examples here but the basic use case is shown in the following snippet: from collections import defaultdict d = defaultdict(int) print(d["someKey"]) //0 The defaultdict can also be used with other types and makes sure that you don't get a KeyError when running your code. Instead, it provides a default value for unknown keys, which can be really helpful for grouping and counting algorithms like the following one: from collections import defaultdict data…
Read More
Diving into advanced Kotlin features

Diving into advanced Kotlin features

Kotlin, Teaching
Diving into advanced Kotlin features (Devoxx UK 2019) This year I gave my first "big conference" talk at Devoxx UK 2019 in London speaking about advanced Kotlin features. I targeted this talk towards an audience with intermediate Kotlin skills. Therefore I assumed that most of the standard language features, e.g., extension functions, class definitions, properties, and so on were familiar already, so I didn't explain everything during the session. The advanced Kotlin features I covered are listed next: Infix Functions Operator Overloading Higher Order Functions and Inling Lambdas with Receiver Domain Specific Languages Delegated Properties Generics and reified types (This topic had to be skipped due to time constraints) Inline Classes Contracts The talk went pretty well overall, although I had to sit during the entire session since the room…
Read More
Kotlin Inline Classes – How they work and when you should use them

Kotlin Inline Classes – How they work and when you should use them

Kotlin, Software Development
Kotlin Inline Classes - How they work and when you should use them Kotlin introduced inline classes with version 1.3 as an experimental feature. You should be aware that their implementation can still change in future releases, but it's already a great time to learn about them now. Inline classes add a simple tool we can use to wrap some other type without adding runtime overhead through additional heap allocations. In this article, we want to see how inline classes in Kotlin work and when it makes sense to use them. Enable inline classes in your project To enable inline classes in your project, you simply need to work with Kotlin version > 1.3 which adds the inline keyword to the language. Since inline classes are still experimental, your IDE…
Read More
How Kotlin makes me a more productive software developer

How Kotlin makes me a more productive software developer

Functional Programming, Java, Kotlin, Software Development
How Kotlin makes me a more productive software developer I've been writing JVM code for more than seven years now, and I did so mainly using Java. This changed about two years ago when I picked up Kotlin. By now, I managed to drop the Java language more-or-less entirely in favor of Kotlin. I did this because I feel much more productive with the language. It lets me focus more on the business logic rather than forcing me to write boilerplate code over and over again. In this post, I tell you how Kotlin makes me a more productive developer. I certainly know Kotlin much better than I ever knew Java. FWIW, I had been certified as a Java expert by Oracle some years back. Still, Kotlin became my native…
Read More
Concurrent Coroutines – Concurrency is not Parallelism

Concurrent Coroutines – Concurrency is not Parallelism

Kotlin, Software Development
PLEASE find an updated version of this on my Medium: https://medium.com/@s1m0nw1/the-difference-between-concurrency-and-parallelism-explained-using-kotlin-83f4159581d. On Kotlin Coroutines and how concurrency is different from parallelism The official docs describe Kotlin Coroutines as a tool "for asynchronous programming and more", especially are coroutines supposed to support us with "asynchronous or non-blocking programming". What exactly does this mean? How is "asynchrony" related to the terms "concurrency" and "parallelism", tags we hear about a lot in this context as well. In this article, we will see that coroutines are mostly concerned about concurrency and not primarily about parallelism. Coroutines provide sophisticated means which help us structure code to make it highly concurrently executable, also enabling parallelism, which isn't the default behavior though. If you don't understand the difference yet, don't worry about it, it will get clearer…
Read More
Hibernate with Kotlin – powered by Spring Boot

Hibernate with Kotlin – powered by Spring Boot

Gradle, Hibernate, Kotlin, Software Development, Spring
Hibernate with Kotlin - powered by Spring Boot In this post, I'd like to demonstrate what you need to consider when using Hibernate with Kotlin. Hibernate is probably the most famous framework for object-relational mapping (ORM) on the JVM, which is used to persistently store Plain Old Java Objects (POJOs) in relational databases. It also implements the Java Persistence API, a specification that "describes the management of relational data" on the JVM. Summary (TL;DR) Put the kotlin-noarg compiler plugin on your build path, it will generate no-argument constructors for your Hibernate entities. In Gradle, add the following to your buildscript dependencies: classpath("org.jetbrains.kotlin:kotlin-noarg:${kotlinVersion}") Further examples can be found here Enable the kotlin-jpa plugin, which works on top of kotlin-noarg by enabling the no-arg generation for Hibernate annotated classes In Gradle, activate…
Read More
Execute Kotlin Scripts with Gradle

Execute Kotlin Scripts with Gradle

Gradle, Kotlin, Software Development, Teaching, Tutorial
Organize Kotlin Scripts as Gradle tasks In this article, you will learn how you can organize multiple Kotlin scripts as Gradle tasks and make them easily executable this way. I've found a discussion about this here. Somebody wanted to execute Kotlin scripts with Gradle build scripts which is, of course, possible by using kotlinc as shown in this (Groovy) build script. This doesn't look very pretty though, and, as described in the corresponding thread, isn't very performant and manageable. Another solution would be to use Gradle scripts written with the Kotlin DSL and define custom tasks within a build.gradle.kts file, which obviously can hold and run Kotlin code naturally: // build.gradle.kts // // Execute Kotlin task with: gradle -q foo task("foo") { group = "com.kotlinexpertise" description = "my foo task"…
Read More