Data Oriented Programming in Java 21, Solving the Countdown game - JEP Cafe #22
Автор: Java
Загружено: 2024-02-08
Просмотров: 29412
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.
You can watch all the episodes on the JEP Café series here: • JEP Café
You can find the code of this episode here: https://gist.github.com/JosePaumard/e...
⎯⎯⎯⎯⎯⎯ 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
19:30 Getting rid of Optional with Stream.mapMulti()
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!
◦ 25 50 75 100 3 6 ➱ 952 • Countdown - The Most Extraordinary Numbers...
◦ 25 50 75 100 1 10 ➱ 813 • Countdown Amazing Calculation 813 - Carol...
◦ 100 9 5 10 4 2 ➱ 566 • Carol Vorderman beaten by 11-year-old on C...
◦ 50 75 100 25 2 1 ➱ 940 • The best numbers game on Countdown 27.10.14
◦ 75 25 50 100 8 2 ➱ 431 • Letters and Numbers - Lily Serna at her am...
◦ 25 100 75 50 6 4 ➱ 821 • LETTERS AND NUMBERS - Incredible Maths Cal...
◦ 3 1 7 8 1 4 ➱ 246 • Nick refuses contestants answer - Countdow...
More resources on Data Oriented Programming and other subjects covered in this JEP Café
◦ Solving the Countdown problem with Java 21's Language Features by Sundar Athijegannathan ➱ https://inside.java/2023/11/03/countd...
◦ Prof. Graham Hutton ➱ https://www.cs.nott.ac.uk/~pszgmh/
◦ Haskell ➱ https://haskell.org/
◦ Haskell Demo by Prof. Graham Hutton ➱ • FP 2 - Haskell Demo
◦ The JEP 461 about Stream Gatherers ➱ https://openjdk.org/jeps/461
◦ Nicolai on Gatherers ➱ • Better Java Streams with Gatherers - Insid... and • Implementing New Java Stream Operations
◦ Dev.java ➱ https://dev.java
◦ Inside.java ➱ https://inside.java
◦ JDK 22 ➱ https://openjdk.org/projects/jdk/22
◦ JDK 21 ➱ https://openjdk.org/projects/jdk/21
◦ JDK 17 ➱ https://openjdk.org/projects/jdk/17
◦ OpenJDK ➱ https://openjdk.org
◦ Oracle Java ➱ https://www.oracle.com/java/
Tags: #Java #Java21 #OpenJDK #JDK #JDK21 #JEPCafe #insidejava
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: