What are generics, anyway?

Recently, I had to explain what generics are and how they are used in the Java language. In a nutshell. Within a couple of minutes.

I ended up stating that generics are a mechanism that allows us to write code that does not care about the type of objects it is handling while at the same time giving enough information to the compiler to preserve type safety. Kind of a note left behind for the compiler.

Photo by Kelly Sikkema on Unsplash

Let us get started with the classic example of a list. Forgetting for a moment that List and LinkedList are generic types, the following…

Solving concurrency problems when working with JPA, Hibernate and Spring Data.

Photo by Tobias Fischer on Unsplash

As soon as different threads on an application — or different application instances in a microservice ecosystem — need to make changes to the same database table, eventually, race conditions will surface.

By operating on the same table, those different threads will eventually want to update the same row. Without further controls, some updates will be silently lost…

During a recent code review, I had to think about alternative solutions to the data model of a simple message processing flow.

For the sake of this article, let’s assume that we’re talking about some webshop customer data: address and payment method.

A system of record contains this data and publishes events every time that a section of it is updated.

So, every time that a customer updates their address, a CustomerAddressChanged message is posted. Likewise, a CustomerPaymentMethodChanged message is posted when the customer edits their payment options.

Message models are already defined by the system of record. The payload…

An introduction to concurrent programming

A computer program is a nicely ordered flow of instructions, executed one after the other from start to finish… Except when it is not. We often wish to split this flow. Let’s see why and when to do it.

So, what’s concurrent programming?

The traditional way of writing programs is to express them sequentially. When one input is received, an output is produced by executing a number of tasks in order. Then the program becomes ready to process the next input, over and over again.

Figure 1 — sequential computing

This way of working matches how machines with a single processing core work. A…

How coroutines make it easier.

Concurrent software is hard to get right, as we’ve seen in the previous article, “When flows split”. Concurrency is even harder to express. Most concurrent code is being written in a way that makes our heads spin every time we need to read it. Let us see how Kotlin helps us write concurrent code that is clearer and more efficient from the start.

This help comes under the form of first-class support for coroutines.

Of course, now one question begs to be asked: what are coroutines?

We are all familiarised with the concept of a…

Vasco Veloso

I'm a polyglot senior software developer, currently interested in software design and architecture.

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