Data Oriented Programming in Java 21, Solving the Countdown game - JEP Cafe #22

preview_player
Показать описание
In this JEP Café, we will use a lot of the new features added to the JDK in the context of the Data Oriented Programming support: Records, Sealed Types, Pattern Matching, Unnamed Patterns, Exhaustive Switches, as well as the most recent additions to the Stream API: mapMulti(), and Gatherers (a preview feature of the JDK 22). As a bonus, you will see an anonymous class used as a non-denotable type in action, to create a small wrapper on a mutable content. All this is used to solve a funny problem: the Countdown game, where you need to reach a target with a set of randomly drawn numbers, and the four arithmetic operations. Let us check if all this can take us to an efficient, and readable solution.

⎯⎯⎯⎯⎯⎯ Chapters ⎯⎯⎯⎯⎯⎯

0:00 Do you feel like a coffee break?
0:11 Introducing the Countdown game and its rules
03:01 Introducing the Haskell algorithm translated to Java
04:44 Computing all the permutations of all the subsets
07:20 Splitting the sets to apply the four operations
08:53 Filtering the invalid operations
09:55 Computing the final result and the string of characters
10:21 Using Data Oriented Programming to model the data
12:05 Wrapping up this algorithm
14:49 Writing a bottom up algorithm leveraging Data Oriented Programming
17:32 Using Optional to discard invalid mapping operations
21:37 Implementing resolve() with an exhaustive switch and pattern matching
23:00 Using a Gatherer to inserting an element at a specific place in a sorted stream
27:18 Using anonymous classes and non-denotable types
28:23 Using the Gatherer in the final process
29:00 Making the algorithm efficient
30:59 Writing the final algorithm using Records
31:50 Comparing the two algorithms
32:33 That's it for today, talk to you soon!

⎯⎯⎯⎯⎯⎯ Resources ⎯⎯⎯⎯⎯⎯

Some amazing Countdown episodes!
More resources on Data Oriented Programming and other subjects covered in this JEP Café

Tags: #Java #Java21 #OpenJDK #JDK #JDK21 #JEPCafe #insidejava
Рекомендации по теме
Комментарии
Автор

Finally, Java is flexing on its multi-paradigm design

giovanninabil
Автор

Great video as always José, with some truly insightful content! However, I personally miss the old format where you would code live and explain your thought process as you go.
It helped me understand not just the 'what, ' but also the 'why' behind each line of code.
Looking forward to more great content!

emileastih
Автор

Very good, in depth explanation. Thank you.

I wrote similar algorithm for solving countdown numbers game long time ago, when I was still at university. It was challenging, but fun problem to solve. I spent couple of weeks on it, on and off, and in the end I come up with quite elegant general solution, although I don’t know if it was as efficient as the solution described in your video.

mirogula
Автор

Great ideas but complex code in general :)

AleksandarT
Автор

We should have another one where Java's support of Functional / Data-oriented programming paradigms is investigated. It can also detail which Java libraries are built on which paradigm, etc

Ambusher
Автор

Hi, guys! Why there are no more any new videos of Java Cafe? I'm so waiting for them :)

anyone-di
Автор

Is the DIV case at 21:24 supposed to have `resolve(left) % resolve(right)` instead of `resolve(right) % resolve(right)`?

TehBrian
Автор

28:23 I don't think you really need that initializer block, you might as well just assign the value in the field declaration directly, e.g. `Element previous = toBeInserted;`

jay_sensz
Автор

Where can I get that Java coffee cup? I can’t seem to find it anywhere!?

danwhitfield-wkbf
Автор

Where can we get that Java coffee mug ❤😊

nigelt
Автор

when @Functional interface contains only one abstract method then why comparator interface contains two abstract methods

dhankumarbajoliya
Автор

Why does everything need to be a gimmick? What is wrong with just presenting the code and functionality? Adult programmers don't need gimmicks like coffee intro and backstory. Just get to the point please.

baronvonherzenberger
Автор

😂 “Data” oriented programming. It’s just functional programming that is old as shit

ChannelCheesecake
Автор

Why compareElement(e1, e2) method has to rely on the premise e2 >= e1 in their implementation Integer.compareTo(e2, e1) ? Integer.compareTo(e1, e2) doesn't works

ampcgmail