Pesticide: A library to write Domain-Driven Tests

Ladybug — a natural pesticide. https://pixabay.com/users/cocoparisienne-127419/

I am sorry about it, but I neglected this blog recently, the reason is that I’m currently trying to write a book explaining how to write complete applications in a functional way with Kotlin. This is taking a ridiculous amount of time because I need to explain functional programming principles while also writing a realistic web application (including database, progressive enhancement, auth-auth. etc.). Well, I hope it will be worth the effort. If you are interested you can sign-up for updates here.

As an aside, while working on the book, I have also created an Open Source library to write…


See how the new compiler can make Kotlin run faster

Photo by Alex Holyoake on Unsplash

More than a year ago I wrote a post about GraalVM performance in Kotlin for the Java Advent Calendar 2018.

It’s time to re-evaluate the results using the new GraalVM v.20.0 and with both the Community Edition and the Enterprise Edition of GraalVM.

You may have heard of Graal, the new JIT compiler for the JVM written in Java. It is available inside the JDK since Java10 and sometime in the future could become the standard compiler in the JDK.

If you are interested, you can find more information here: https://www.infoq.com/articles/Graal-Java-JIT-Compiler

Quick introduction

Since Java 1.3 HotSpot contains two Just In Time…


What is a legacy system? It is old software that is very hard to maintain, to extend, and to improve. On the other hand, it is also a system that is working and is serving the business, otherwise it would not have survived.

Perhaps, when it was first created, a legacy system had an excellent design, a design so good that people started to say, “Okay, maybe we can use it also for this, and this, and this.” It becomes overloaded with technical debt, but it still works. These systems can be amazingly resilient.

Still, developers hate working on legacy…


Exploring the performance improvements of new Inline Types

I wrote this article for the Java Advent Calendar 2019. I am republishing it here with some minor corrections.

https://pixabay.com/photos/fantasy-beautiful-dawn-sunset-sky-3077928/

Project Valhalla is one of the most exciting projects regarding the future of Java and all JVM. It is still in an experimental state, but in this post, we will look at how to try it, and we will implement a small program to verify the kind of performance improvements are possible with it.

Valhalla aims to bring a new Inline Types (aka Value Types) that will: “Codes like a class works like an int”.

Currently, in the JVM there are…


Understanding how tailrec keyword works and how to take advantage of recursion in Kotlin

Image credits: https://pixabay.com/illustrations/fractal-abstract-red-white-stripes-542155/

It is already passed a year since I wrote the first Kotlin Pearl blog post. Thanks to everybody (and you are really a lot) who supported me and clapped or liked my posts.

This post will cover:

  • How to solve a problem using recursion
  • How to transform Head Recursion into Tail Recursion
  • The tailrec keyword and how it’s translated in ByteCode
  • How to implement the Y-Combinator in Kotlin

Recursion is a powerful technique, it allows us to define a complex problem in terms of solving a simpler version.

The main characteristic of a recursive function is that at some point…


How to take advantage of Kotlin special Types

Image credits: https://pixabay.com/photos/tori-japanese-shrine-torii-1976609/

It should be apparent, even to the casual reader of this blog, that I really like Kotlin as a language. One of the reasons is its Type Hierarchy, which is both very easy to work with and extremely powerful. It is also quite close to the Java Type System, so the interoperability is excellent.

To take full advantage of Kotlin Type Hierarchy is essential to understand how these three special types do work.

We will look in detail at Unit, Nothing, Any and compare their use against Java corresponding classes.

Finally, we also consider null and how types ending with…


I’m just returned from @JCreteUnconf, which is an amazing unconference about Java-related technologies in the island of (you guessed) Crete.

I’ve already described my previous attendance here.

Both the people and the location makes every edition of JCrete an unforgettable event.

First of all, thanks to @heinzkabutz and all disorganizers (the organizers of an unconference) @ixchelruiz @kcpeppe @aalmiray @marcandsweep @gsaslis @DVyazelenko

(a special hello to @rgransberger who wasn’t there this time for a very good reason but she did so well at disorganizing all past editions)

In an unconference, everybody is a speaker and everybody can propose an argument of…


An investigation inside how Kotlin let you use Java collections as if they were implementing Kotlin interfaces

This post is a little more low-level than my recent posts about Kotlin Pearls, so brace yourself to a tour on the inner workings of Kotlin.

“Only heavens are immutable” — Aristotle

Part I — the surprise

It started with a (mostly) harmless piece of code.

I wanted to show why it is not right to assume that List in Kotlin is immutable. The reason is that MutableList inherits from List:

public interface MutableList<E> : List<E>, MutableCollection<E> {...}

So, if you think about it, it means that you can pass a MutableList where a List is expected, but you cannot pass a List where a MutableList is expected. …


How to use Extension Functions and Properties to improve the readability of your code

To Extend or Not To Extend?

Extension Functions (and properties) are a new thing for Java developers, they are present in C# since long but they landed in the JVM land for the first time by courtesy of Kotlin.

Working on big Kotlin codebase and browsing through open source Kotlin code, I have noticed some recurring cases where extensions are useful to improve code readability and some cases where they make the code more difficult to understand.

This is also a hot topic of discussions in teams that are starting Kotlin for the first time, so I think there is some value to make a summary…


And other useful tricks of Implementation By Delegation

This is the fifth article in a series about little known features of Kotlin.
You can find the previous posts here here here and here.

Another kind of multiple inheritance…

Let’s talk today about what used to be my least favorite Kotlin feature: the by keyword. It was my least favorite because I saw it useful for a very limited number of use cases only and it was an unnecessary complication.

I discovered later that on the contrary, it works very well together with other Kotlin features and it is really beneficial if you know how to use it wisely.

First things first: the by

Uberto Barbini

JVM and Kotlin independent consultant. Passionate about Code Quality and Functional Programming. Author, public speaker and OpenSource contributor.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store