Posts

  • Raise Your Tests: Testing Functional Kotlin with Arrow and Raise

    A wide-randing guide to testing your functional Kotlin code with Arrow and the Raise DSL. [continue...]
  • Kotlin Flows - The Ultimate Guide

    This article thoroughly covers a crucial concept in Kotlin Coroutines: Kotlin Flows. Flows are a reactive data structure you probably didn't know, but you can't live without them once you know them. [continue...]
  • Type Classes in Kotlin: A Practical Guide

    In this article, we delve into the concept of type classes in Kotlin, a powerful tool that allows developers to abstract logic for different data types. We’ll take data validation as an example to show how type classes can be used to write generic and reusable code. Our implementation will be based on the Arrow Kt library, which will exploit Kotlin’s context receivers. [continue...]
  • Functional Error Handling in Kotlin, Part 3: The Raise DSL

    It’s time to end our journey on functional error handling in Kotlin with the new features introduced by the Arrow library in version 1.2.0, which previews the significant rewrite we’ll have in version 2.0.0. We’ll mainly focus on the Raise DSL, a new way to handle typed errors using Kotlin contexts. [continue...]
  • Kotlin Context Receivers: A Comprehensive Guide

    This article will explore a powerful feature of the Kotlin programming language called context receivers. If you’re a Kotlin developer looking to write cleaner and more expressive code, context receivers are a tool you’ll want in your toolbox. [continue...]
  • Functional Error Handling in Kotlin, Part 2: Result and Either

    In this series first part, we introduced some of the available strategies to handle errors in a functional fashion using Kotlin and the Arrow library. In this second part, we’ll continue our journey by looking at the Result and Either data types and how to use them to handle errors in a functional way. [continue...]
  • Functional Error Handling in Kotlin, Part 1: Absent values, Nullables, Options

    Whether we develop using an object-oriented or functional approach, we always have the problem of handling errors. Kotlin offers a lot of different methods to do it. Here, we'll focus on strategies that deal with the error without managing its cause, i.e., nullable types and Arrow Option types. [continue...]
  • The Ultimate Guide to Java Virtual Threads

    Version 19 of Java came at the end of 2022, bringing us a lot of exciting stuff. One of the coolest is the preview of some hot topics concerning Project Loom: virtual threads (JEP 425) and structured concurrency (JEP 428). Whereas still in a preview phase, the two JEPs promise to bring modern concurrency paradigms also in the mainstream language of the JVM: The Java programming language. [continue...]
  • Kotlin Coroutines - A Comprehensive Introduction

    Coroutines are a powerful tool for asynchronous programming, and they fall under the umbrella of structured concurrency. Let's see together which are their main features and strengths. [continue...]
  • A Scala project with Akka, Cats and Cassandra

    This article will show you how to write a bigger project involving Akka (typed) Actors, Akka (typed) Persistence, Cassandra, Akka HTTP, and Cats. We’re going to write a mini-bank application, where users can create bank accounts, retrieve their details and interact with their bank account to deposit/withdraw money. [continue...]
  • FS2 Tutorial: More than Functional Streaming in Scala

    We rely on the JDBC specification if we need to connect to SQL databases in the JVM ecosystem. However, JDBC is not a good fit if we use functional programming since the library performs a lot of side effects. Fortunately, a library called Doobie provides a higher-level API on top of JDBC. [continue...]
  • Learn Doobie for the Greater Good

    We rely on the JDBC specification if we need to connect to SQL databases in the JVM ecosystem. However, JDBC is not a good fit if we use functional programming since the library performs a lot of side effects. Fortunately, a library called Doobie provides a higher-level API on top of JDBC. [continue...]
  • Kafka Streams 101

    Apache Kafka is clearly the leading technology concerning message brokers. It’s scalable, resilient, and easy to use. Moreover, it leverages a bunch of exciting client libraries that offer a vast set of additional features. One of these libraries is Kafka Streams. [continue...]
  • ZIO Kafka: A Practical Streaming Tutorial

    Apache Kafka has prove itself to be a reliable, scalable and efficient communication system between distributed application components. In this article, we'll learn to use ZIO to interact with it. [continue...]
  • ZIO: Introduction to Fibers

    Many libraries implement the effect pattern in the Scala ecosystem, and every one has its own concurrency model. First, let's introduce the ZIO library and its implementation of the fiber model. [continue...]
  • Unleashing the Power of HTTP Apis: The Http4s Library

    Nowadays, many applications expose APIs over an HTTP channel. So, it’s worth spending some time studying libraries implementing such use case. If we learned the basics of functional programming using the Cats ecosystem, it’s straightforward to choose the http4s library to implement HTTP endpoints. Let’s see how. [continue...]
  • The Tagless Final Pattern in Scala

    Whether we prefer to use object-oriented programming or functional programming, every paradigm has its own patterns to manage dependencies among modules when managing big programs. In recent years, functional programmers prefer the Tagless Final pattern. [continue...]
  • Value Classes in Scala

    One of the main rules of functional developers is that we should always trust a function’s signature. Hence, when we use functional programming, we prefer to define ad-hoc types to represent simple information such as an identifier, a description, or a currency. Ladies and gentlemen, please welcome the value classes. [continue...]
  • Typed Mailboxes in Scala

    Mailboxes are one of the fundamental parts of the actor model. Through the mailbox mechanism, actors can decouple the reception of a message from its elaboration. So, let’s see how Akka Typed, the most famous incarnation of the actor system, implements the concept of mailboxes. [continue...]
  • Algebraic Data Types (ADT) in Scala

    Every developer using Scala meets the acronym ADT sooner or later. But, what are Algebraic Data Types? Why are they so useful? In this article, we will try to answer all of your questions about ADT. [continue...]
  • Hold My Beer - Apache Kafka and More

    The video presents the meetup on Apache Kafka made by AgileLab, in which I was one of the main speakers. During the video, I present the basics of Apache Kafka, and the principles behind the Hexagonal architecture [continue...]
  • Monads in Scala

    As developers, we often encounter the need to encapsulate values with some additional context that cannot be directly related to the business domain. For example, we often need a value to be in a sequence or computed asynchronously. Monads are the mechanism we can use to fulfill such needs. Let’s understand them by looking at some examples. [continue...]
  • Map a Future for both Success and Failure in Scala

    A Future in Scala allows us to treat concurrency in a declarative way, hiding the complexity of asynchronous programming. We can map a Future, changing the value computed concurrently. But, what about a failed Future? Can we map something that fails into a new value? In this tutorial, we’ll explain exactly how to do just that. [continue...]
  • Supervision and Monitoring in Akka

    The reactive manifesto, the guideline for all reactive systems, states that a distributed application should be resilient. To achieve resiliency, we must develop systems that treat failure as a first-class citizen in the architecture. The Akka library, through the mechanism of supervision, provides the primitives to implement resilient systems. In this tutorial, we’re going to show how to use Akka and supervision to improve the resiliency of distributed systems. [continue...]
  • Akka Interaction Patterns: Request-Response

    After having introduced the Tell Pattern, it’s time to make an overview of some interaction that is more frequent in real-world scenarios: the request-response pattern. [continue...]
  • Akka Interaction Patterns: The Tell Pattern

    After the introduction to the library Akka Typed, it’s time to go deeper and describe one of the main interaction patterns between actors: the Tell Pattern, also known as fire and forget. [continue...]
  • The Cake Pattern

    In our tutorial on Scala’s Self-Type Annotation, we saw how to use self-type annotations to declare dependencies among types. Now, it’s time to go further. Let’s talk about the Cake Pattern, an idiomatic implementation of the Dependency Injection pattern in Scala. [continue...]
  • Self-Type Annotation in Scala

    The Scala programming language has many ways to handle dependencies among types. The so-called “self-type” annotation allows us to declare dependencies using traits and the concept of mixins. In this tutorial, we build a small test execution framework using the self-type annotation. [continue...]
  • Typed Akka: The Actor Model Done Right

    The Actor Model is a very promising concurrent programming model. One of its most successful implementations is Akka, which is the reference implementation on the JVM. In this tutorial, we’ll discuss the actor model’s main features and how Akka implements them in its last version, the Akka Typed library. [continue...]
  • Variances in Scala

    In this tutorial, we will be looking at Scala variances. Variance tells us if a type constructor (equivalent to a generic type in Java) is a subtype of another type constructor. We’ll also take a look at the three main types of variance – invariance, covariance, and contravariance – and how they differ. [continue...]
  • A Comprehensive Guide to For-Comprehension in Scala

    In imperative programming languages, we use loops such as for-loop and while-loop to iterate over collections. The Scala programming language introduced a new kind of loop: the for-comprehension. Its use goes far beyond simply looping over collections, helping us to deal with the complexity of the syntax when using a functional approach to programming. [continue...]
  • To Trait, or not to Trait?

    Developers coming from object-oriented languages such as Java or C# know very well the difference between abstract classes and interfaces. The Scala programming language introduced a third contestant in the match: Traits. [continue...]
  • ...And Monads for (Almost) All: The Reader Monad

    I have already written of dependency injection mechanisms in modern programming languages. I wrote about the Cake Pattern and how to use Scala self types to resolve the problem of dependency injection. Then, I showed how to use Scala implicits to implement a dependency injection mechanism. Now its time to speak about how functional programming tries to solve the dependency management issue, using the Reader Monad. [continue...]
  • The Pimp My Library Pattern

    Which is the main problem you have as a developer when you use libraries that you don't own? You can't change them. If something is missing in the public API of a library, there is no chance to extend it. Using some excellent old object-oriented programming, you can overcome this problem by writing much boilerplate code. In the JVM ecosystem, modern programming languages, such as Scala, Kotlin or Groovy, try to give a solution to library extension, the Pimp My Library Pattern. [continue...]
  • Optional Is the New Mandatory

    Since the beginning of the 'computer programming era', developers had searched for a solution for one of the biggest mistake made in computer science, the invention of the null reference. Since functional programming became mainstream, a solution to this problem seems to arise, the use of the optional type. [continue...]
  • It's a Kind of Magic: Kinds in Type Theory

    I am not an expert of functional programming, nor type theory. I am currently trying to enter the world of Haskell after I mess around the Scala world for a while. When I read about Kinds, I remember I was surprised, and a little bit scared. Is it possible that types have types? So what does this mean? In this little introductory post, I will try to explain to myself what I understood during my journey through kinds in my Haskell travelling. [continue...]
  • ...And Monads for (Almost) All: The State Monad

    This article starts a series on a topic that is very hot among the developers' community: functional programming. In details, we will focus on monads. The main aim of monads is to make simpler the composition of pure functions, that are mathematical functions that cannot have any side effect. We start with a classic: The State Monad. As its name suggests, using this object, we will be able to manage the state of a program effectively, without breaking one of the main principles of the paradigm, immutability. [continue...]
  • The Secret Life of Objects: Inheritance

    This post is the second part of a series of posts concerning the basic concepts of Object-Oriented Programming. This time, I focus on the concept of Inheritance. Whereas most people think that it is easy to understand, the inheritance is a piece of knowledge that is very difficult to master correctly. It subtends a lot of other object-oriented programming principles that are not always directly related to it. Moreover, it is directly related to one of the most potent forms of dependency between objects. So, let's get this party started. [continue...]
  • The Secret Life of Objects: Information Hiding

    I've been in the software development world for a while, and if I understood a single thing is that programming is not a simple affair. Also, object-oriented programming is even less accessible. Last week I came across a blog post -Goodbye, Object Oriented Programming-. After having read it, I fully understand how easily object-oriented programming can be misunderstood at many levels. I am not saying that I have the last answer to the million dollar question, but I will try to give a different perspective of my understanding of object-oriented programming. [continue...]
  • Template Method Pattern Revised

    When I started programming, there was a design pattern among all the others that surprised me for its effectiveness. This pattern was the Template Method pattern. While I proceeded through my developer career, I began to understand that the inconsiderate use of this pattern could lead to a big headache. The problem was that this pattern promotes code reuse through class inheritance. With functional programming became mainstream, this pattern can be revised using lambda expressions, avoiding any inheritance panic. [continue...]
  • Single-Responsibility Principle done right

    I am a big fan of SOLID programming principles by Robert C. Martin. In particular, I thought that the Single-Responsibility Principle was one of the most powerful among these principles, yet one of the most misleading. Its definition does not give any rigorous detail on how to apply it. Every developer has left to his own experiences and knowledge to define what a responsibility is. Well, maybe I found a way to standardize the application of this principle during the development process. Let me explain how. [continue...]
  • A Cameo that is worth an Oscar

    Rarely, during my life as a developer, I found pre-packaged solutions that fit my problem so well. Design patterns are an abstraction of both problems and solutions. So, they often need some kind of customization on the specific problem. While I was developing my concrete instance of Actorbase specification, I came across the Cameo pattern. It enlighted my way and my vision about how to use Actors profitably. Let's see how and why. [continue...]
  • Resolve me, Implicitly

    Reading my posts you can easily find that there is a topic that cares about me a lot: Dependency management in the development process. There is a feature of the Scala programming language that I liked since the beginning. Without any external library, it is possible to successfully implement vary dependency injection mechanisms. In the past, I wrote about the Cake pattern. Now it's time to talk about dependency injection through the use of implicits. Let this race starts! [continue...]
  • Object-Oriented Programming strikes back!

    Recently I read the article "Beginning to Doubt Object-Oriented Programming" on DZone. It is not the first post that I find on a blog that praises functional programming with respect to object-oriented programming. For all of this posts, object-oriented programming is dead (more or less). I think that at the basis of all this posts there is a misunderstanding over what functional programming really is. Now it's time for me to give my two cents to the fight among different programming paradigms. [continue...]
  • Machine Learning: A gentle introduction

    Looking at the last Google and Apple conventions it was clear to all: if in the past years the main buzzwords in the information technology field were IoT and Big Data, the catch'em all word of this year is without any doubts Machine Learning. What does this word exactly means? Are we talking about artificial intelligence? Somebody is trying to build a Skynet to ruin the world? Machines will steal my job in the future? Know your enemy, they said. So let's try to understand what Machine Learning really means. [continue...]
  • Test Proven Design

    Just a couple of days ago, I was surfing through the code base of the project I am actually working on when I found something that disgusted myself a lot. I smelled that something was wrong. Then, I checked unit tests associated to the class. Bingo, tests were not complete. Tests' incompleteness did not highlight a problem in class design. Let's look how tests can improve the architecture of software that we develop everyday. [continue...]
  • Dependency.

    What does the concept of dependency mean in programming? Is it important in modern development process? Has the concept of dependency a different meaning when we speak about procedural programming, object oriented programming or functional programming? In this post I will try to sum up all the knowledge I gained during my life as a software developer. [continue...]
  • Implementing Time Series in MongoDB

    I came recently to design a solution for MongoDB to store information that has time as the main axis of analysis. This information should be stored in a way that is easy enough to query and aggregate using many different time granularity (monthly, weekly, daily, ...). Information should also be stored in a way that does not consume too much disk space and is optimal in performance for MongoDB to maintain. In a word, I need to transform MongoDB in a Time series database. [continue...]
  • Code looks like a Chain

    As Aerosmith sang many years ago, “Code looks like a Chain.” No? They didn't say that? Maybe I'm remembering it wrong. Well, as you might have guessed, in this post, we'll talk about the Chain of Responsibility design pattern. This pattern is not one of the more popular ones, at least among the patterns defined by the Gang of Four, but modern dependency injection frameworks give us the possibility to implement it in a smart, and fresh way. Let’s see how. [continue...]
  • Scala is dead, long live Scala!

    Recently I came across yet another post about the adoption of Scala in the IT world nowadays. The article is 'The Rise and Fall of Scala' on DZone. In that post the author describes the reasons of the failure of the Scala language in becoming the next big general purpose programming language. But, are we sure that authors of Scala ever pretend the language to be used by every developer on the Planet? I don't think so. [continue...]
  • Try again, Apache Spark!

    It's been more than a year since I've started working on my first Big Data project. In this project we chose Apache Spark as batch processing framework. Using Apache Spark throws you in a functional, distributed and asynchronous programming world. While you have not to worry about the distributed adjective, because Spark hides you every problem related to it, the functional and asynchronous adjectives make things more complex with respect to the error handling process. Let's explain why. [continue...]
  • Resolving your problems with Dependency Injection

    'No Silver Bullet' wrote Brooks in the far away 1986. The history of software engineering proved him right, there is no doubt. Through the past years, hundreds of theories, patterns, frameworks, technologies risen as fast as they successively fallen. Dependency injection broke down the developer community from its definition. In this post I will introduce the pattern, giving the basis for developing a discussion on pattern pros and cons in the next post of this series. [continue...]
  • A new way to err, Apache Spark

    Apache Spark is a library that let you write code that will be executed in a distributed fashion as a simple single threaded program. Spark will make the dirty job for you: it will distribute the code and the execution, manage remote objects for you, optimize the algorithm for you. However, be aware: there is no kind of magic behind Spark. If you do not deeply understand the logic behind it, you will discover new way to loss your time searching for incomprehensible bugs. [continue...]
  • Actorbase or "the persistence chaos"

    You know, everybody out there is talking about Big data, NoSQL databases, reactive programming and so on. There are a lot of buzzwords that are constantly used in this era and the above are some of these. What if someone decide to put some of those buzzword together? What if we couple NoSQL databases and the actor model? Actorbase is a NoSQL database that uses the actor model as its internal reference model. [continue...]
  • Immutability = Thread-safety

    No, there is not a typo in the title of this post. It is a distorted quotation from the Slipknot song 'People equal s**t'. And more or less this was my reaction when I discovered that in Java immutability is not equals to thread-safety. Not always. Let me explain why. [continue...]
  • You shall not comment!

    When I was attending the course of Computer Science at the University they told me that I have to document my code. In this way, the developers that would come after me could understand easily the code I had wrote. Writing good comments is an hard task, if it is possible at all. In this article I will try to explain you why. [continue...]
  • The Good, the Bad and the Singleton

    If you search for the word Singleton on Google, you will probably come up with a bunch of rants about the fact that this design pattern is the absolute evil on the earth. Is it true? Or is this design pattern totally misunderstood by developers? In this series of articles I will try to analyze the reasons that stay behind those rants and I will try to give my point of view on the issue. [continue...]
  • Handling dynamic id objects in Rational Functional Tester

    Functional testing is an discipline that is becoming more and more requested in software industry. In this article we will focus on Rational Functional Tester and on a problem that affects it: recognition of HTML objects with a dynamic id. [continue...]
  • A (too) short introduction to Scala

    I recently had an introductory talk on the Scala programming language. the aim of the talk was not to be a comprehensive presentation of the Scala programming language. The aim was to introduce the Scala language, putting a stress on the features that made it one of the heirs to the throne of programming. [continue...]
  • Eat that cake!

    We know it, managing dependencies between software components within a project of magnitude rather than trivial could become a hell if not planned properly Scala provides a mechanism to resolve dependencies similar to DI, the *cake pattern*. Unlike DI pattern in other languages, such as Java, C++, etc ... the cake pattern can be used directly with language constructs available in Scala. [continue...]
  • Introducing myself...

subscribe via RSS