Articles

Maîtrisez le programmation orientée données avec Java 21 Record et Pattern Matching [Vidéo]

Découvrez comment maîtriser la programmation orientée données avec Java 21 Record et Pattern Matching dans cette vidéo ! Apprenez à créer des applications plus facilement et plus efficacement.

Dans le monde en constante évolution du développement logiciel, les données jouent un rôle central

The main idea behind record patterns is to provide a concise syntax for declaring and deconstructing records. This allows developers to write more expressive code that is easier to read and maintain. Additionally, record patterns make it easier to work with data-oriented programming paradigms such as functional programming.

JEP 441: Pattern Matching for instanceof

JEP 441 introduces pattern matching for the instanceof operator. This feature allows developers to match an object against a pattern, making it easier to process data. The main benefit of this feature is that it makes it easier to write code that is more concise and readable.

Pattern matching for instanceof also provides a more declarative way of processing data. This makes it easier to write code that is more expressive and maintainable. Additionally, this feature makes it easier to work with functional programming paradigms.

Conclusion

Les dernières améliorations apportées à Java 21 sont une preuve supplémentaire de l’importance que les développeurs accordent à la manipulation et au traitement des données. Les JEP 440 et 441 sont des améliorations significatives qui permettent aux développeurs d’écrire du code plus expressif et plus facile à maintenir. Les patrons de données et le filtrage par instanceof offrent une syntaxe plus concise pour déclarer et déconstruire les données, ce qui facilite la navigation et le traitement des données. Ces améliorations sont un pas en avant pour le développement logiciel et permettront aux développeurs d’améliorer leurs compétences et leurs performances.

Améliorations de Java 21 pour le développement logiciel

Dans le monde en constante évolution du développement logiciel, les données jouent un rôle central. La gestion et le traitement efficaces des données sont une préoccupation primordiale pour les développeurs. En tant que l’un des langages de programmation les plus utilisés, Java reconnaît l’importance de la programmation orientée données avec ses dernières améliorations dans Java 21. Deux propositions d’amélioration Java (JEP) se distinguent : JEP 440 et JEP 441.

JEP 440 : patrons de données

JEP 440 est tout au sujet des patrons de données, une fonctionnalité qui améliore considérablement les capacités du langage de programmation Java en matière de manipulation des données. Les patrons de données introduisent une nouvelle façon de déconstruire les valeurs enregistrées, ce qui rend la navigation et le traitement des données plus déclaratifs et composables.

L’idée principale derrière les patrons de données est de fournir une syntaxe concise pour déclarer et déconstruire les enregistrements. Cela permet aux développeurs d’écrire du code plus expressif qui est plus facile à lire et à maintenir. De plus, les patrons de données facilitent la mise en œuvre des paradigmes de programmation orientée données tels que la programmation fonctionnelle.

JEP 441 : filtrage par instanceof

Source de l’article sur DZONE

This might sound like a joke, but it’s actually not. First, let’s define inheritance. Inheritance is the ability to use polymorphism to override a method with another implementation. You inherit from a class, and you override one of its virtual functions. This results in that code having an object that will no longer invoke the old base class method, but rather the new overridden method. Kind of easy, right?

Polymorphism Is the Ability To Have Old Code Invoke New Code

Well, there’s nothing intrinsically special about class-based OOP that prevents you from implementing the above in a functional context. In a functional programming language, you can have a reference to a function, and replace the function it’s pointing to, before passing in your function reference to some method in need of a function with the specified signature. This achieves the exact same result as « classic polymorphism. »

Source de l’article sur DZONE

For the last few years, I’m writing articles that describe a new, more functional way to write Java code. But the question of why we should use this new coding style remains largely unanswered. This article is an attempt to fill this gap.

Just like any other language, Java evolves over time. So does the style in which Java code is written. Code written around Y2K is significantly different from code written after 2004-2006 when Java5 and then Java6 was released. Generics and annotations are so widespread now, that it’s hard to even imagine Java code without them.

Source de l’article sur DZONE

Project Lambda is an effort to bring Java into the world of functional programming. 

Lambda is a function without a name. It is an implementation of functional interfaces. A functional interface is an interface that has only a single custom abstract method that isn’t inherited from the object class. In Java, interfaces such as Runnable, Comparable, and many others are the example of Functional Interfaces. It defines an anonymous implementation for one-time use and significantly streamlines your code.

Source de l’article sur DZONE

This article is for the Scala programmer who has at least used or heard about Futures before. You can also find this over at the Rock the JVM blog or on YouTube in video form or embedded below:

In this article, I’m going to address the problem of "deterministic" Futures in Scala. You probably know by now that Futures are inherently non-deterministic, in the sense that if you create a Future
Scala

You know the value inside will be evaluated on "some" thread, at "some" point in time, without your control.

The Scenario

Here, I will speak to the following scenario which comes up often in practice. Imagine you’re designing a function like this:
Scala

with the assumption that you’re issuing a request to some multi-threaded service which, is getting called all the time. Let’s also assume that the service looks like this:
Scala

The service has two API methods:
  1. A "production" function that is completely deterministic.
  2. A submission function that has a pretty terrible API because the function argument will be evaluated on one of the service’s threads, and you can’t get the returned value back from another thread’s call stack.
Let’s assume this important service is also impossible to change, for various reasons (API breaks, etc). In other words, the "production" logic is completely fixed and deterministic. However, what’s not deterministic is when the service will actually end up calling the production function. In other words, you can’t implement your function as:
Scala

because spawning up the thread responsible for evaluating the production function is not up to you.

The Solution

Introducing Promises — a "controller" and "wrapper" over a Future. Here’s how it works. You create a Promise, get its Future and use it (consume it) with the assumption that it will be filled in later:
Scala

Then pass that promise to someone else, perhaps an asynchronous service:
Scala

And at the moment, the promise contains a value. Its future will automatically be fulfilled with that value, which will unlock the consumer.

How to Use it

For our service scenario, here’s how we would implement our function:
Scala

We create a promise and then we return its future at the end for whoever wants to consume it. In the middle, we submit a function that will be evaluated at some point out of our control. At that moment, the service produces the value and fulfills the Promise, which will automatically fulfill the Future for the consumer.
This is how we can leverage the power of Promises to create "controllable" Futures, which we can fulfill at a moment of our choosing. The Promise class also has other methods, such as failure, trySuccess/ tryFailure and more.
I hope this was useful!

Source de l’article sur DZONE


Java 8
No matter what version of the JDK we are on, Java 8 is not going anywhere.

Java 8 introduced a new era of Java. Everything from lambda expressions and functional programming to Streams and collections — DZone was there to document it all.

So whether you’re migrating over to Java 9 or Java 11, or maybe even Java 13, Java 8 concepts and features are still very much alive in the JDK. And understanding these core concepts can help tremendously when it’s time to move beyond Java 8.

Source de l’article sur DZONE

This article is dedicated to the non-commercial Java conference that I visited on September 24, 2019, in Hannover, Germany, known as Java Forum Nord. The spoken language is German but the presentations consist of diagrams and code examples so they can be understood by the non-German-speaking readers. I want to list here the lecture which I have visited with links to the presentations and also lists with headwords.

Networking Instead of Waste: Let’s Talk — Stefanie Reinicke, Dr. Jan-Christian Dammann

This presentation was about making development teams stronger through three topics:

Source de l’article sur DZONE

As I covered in a previous post, monad transformers have poor performance properties in languages and runtimes unequipped to deal with them — including the Scala programming language and the JRE.

There’s a general technique to improving performance that involves something I call effect rotation.

Source de l’article sur DZONE

I wouldn’t class myself as a JavaScript developer, I always joke that it’s a language I never meant to learn. It’s so pervasive now, it just happened. I go through phases of enjoying it and despising it. But through the peaks and troughs of love and not quite hate. One problem persisted: if I’m to be a good JS developer and write functional JavaScript, how then do I write code in a way that implies a proper domain model?

In traditional OO languages, such as Java, C#, and even Go actually, it’s easy to write code that’s architected around a domain design. You have classes, which are big and do a lot of stuff. Which of course is something you generally avoid like the plague in JavaScript, for fair enough reasons.

Source de l’article sur DZONE