deduplication API

Deduplication trick in legacy code

It might happen that you need to deduplicate a list of items…​ coming from legacy code. The class - let’s call it LegacyObject has already implementations for equals() and hashCode(). It’s not possible to change the implementation, for fear of breaking the running code. And unfortunately, the Java API doesn’t offer a distinctBy() feature. In that case, a cheap trick is to create a wrapper class around LegacyObject, with the desired implementation: public class L

Kotlin software design UML

Options for managing derived attributes in Kotlin

A derived attribute is an attribute computed from other attributes e.g.: The fullName is aggregated from the first, middle and last nameThe age is computed from the birthdateetc. Kotlin offers different options to manage such derived attributes. Let’s browse through them. Inline field initialization The simplest way to manage derived attributes is to declare a property, and compound its declaration with its initialization: class Person(val firstName: String, val middle

Spring DevTools Maven Jib IntelliJ IDEA tip

Spring DevTools with Jib and IntelliJ IDEA

I’ve been recently developing a Spring Boot application, and to speed up my development speed, I added Developer Tools as a dependency. By default, classes loaded in the HotSpot JVM can be updated only if the later runs in debug mode, and only for changes regarding method implementation. This means adding an attribute to an class requires a full restart. DevTools is an improvement over that. It works by tweaking the standard classloading mechanism: one classloader is dedicated to librar

streams Functional Programming state Object-Oriented Programming

Java streams and state

With Java 8 streams, it seems Functional Programming has won. Long live statelessness and recursion! Reality is a bit more nuanced: as always in software programming, it depends. I believe that the more tools in your toolbelt, the better it is. When all you have is a hammer, everything looks like a nail. In Functional Programming, every function needs to be pure: output only depends on input, and there are no side-effects. For this reason, Java methods to create infinite streams are not u

Functional Programming group by

From Imperative to Functional Programming: a grouping issue (and how to solve it)

This is the third post in a series about migrating to functional programming: From FP to imperative using ArrowFrom FP to imperative, an approach There’s a whole category of problems related to grouping e.g.: given a collection of person, return a list of pairs with the first value the age, and the second one the collection of persons of that agegiven a collection of orders, return a list of pairs with some price range e.g. $0-$100, $101-$200, etc. as the first value, and the number of s

Functional Programming paradigm

From Imperative to Functional Programming, an approach

Last week, we ported the migration of a Scala application from imperative to functional in Kotlin with the help of the Arrow library. This was pretty easy: the example was laid out for us. This week, I’d like to go for more fundamental stuff. On HackerRank, there’s this problem: Consider a staircase of size 4: # ## ### #### Observe that its base and height are both equal to n, and the image is drawn using # symbols and spaces. The last line is not preceded by any sp

Functional Programming Arrow IO

From Imperative to Functional Programming using Arrow

Some time ago, I watched the talk FP to the max. While the end of the talk is quite Scala-ish, the beginning can be of interest regardless of the language. In the talk, the speaker tries to migrate a standard imperative-like application using a functional approach. I wanted to check if it was possible to do the same in Kotlin. The original code Translated in Kotlin, the original code looks like the following: private val random = SecureRandom() fun main(args: Array<String>) { pr

Git cloud GitHub GitLab Bitbucket

Git service providers comparison

Since its inception, the attitude of GitHub toward repositories was to allow unlimited public repositories, while make private ones paying. Whether it’s a consequence of Microsoft’s acquisition or not, this stance changed recently: GitHub announced private repositories were also made free, for up to 3 contributors. There was a lot of celebration on the Web, but not from my side. This move looks more like a (desperate?) move to keep developers on GitHub. Whether that’s the case