Тёмный

Clean Code with Records, Sealed Classes and Pattern Matching by José Paumard 

Devoxx
Подписаться 159 тыс.
Просмотров 25 тыс.
50% 1

The releases of the JDK 17 to 19 bring interesting features in the Java language: sealed types, pattern matching for switch (as a preview feature). Along with the introduction of records, the implementation of pattern matching in the Java language begins to take shape. The JDK 19 brings even more with Record pattern matching (as a preview feature), that further simplifies your code. In this presentation we show you how records are working, how you can use them to make your code much more readable, and how you can leverage sealed types and switch expressions to improve the modularity of your application. You will see pattern matching in action on real examples, how it will change the way you write Java code, and what you can expect on this topic in the future. It is mostly a live coding presentation, with some slides when the code shown cannot be executed.
JOSÉ PAUMARD
José works as Java Developer Advocate at Oracle. PhD in applied maths and computer science, assistant professor at the University Sorbonne Paris Nord for 25 years, he is a Java Champion Alumni and JavaOne Rockstar. He is a member of the french Paris Java User Group, has been a co-organizer of the conference Devoxx France, and is a disorganizer of JChateau, an unconference held in the Chateau of the Loire Valley. He works on the dev.java documentation and community website, publishes the JEP Café, a monthly video cast on RU-vid, and maintains a french RU-vid channel with more than 80 hours of Java courses. He is also a Pluralsight author in the Java space.
------------------------------------------------------------
INTRO
visuals & editing by @Mercator
music : Avocado by Ephixa

Опубликовано:

 

14 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 21   
@AyushmanAdhikary
@AyushmanAdhikary 2 месяца назад
Very informative. Always enjoy your content which is conceptually so clear to understand.
@francksgenlecroyant
@francksgenlecroyant 11 месяцев назад
I think the serialization process is using the Constructor even with regular java classes, the reason why the validation rule is not triggered is because, the constructor which is involved here is the default non-args constructor. That's it!
@MrGabblit
@MrGabblit 2 года назад
Very insightful, well presented talk
@EmmanuelBLONVIA
@EmmanuelBLONVIA Месяц назад
13:38 Introducing a security breach in java solved by records 14:03 When you deserialize an object, no constructor is called 😳 14:30 here's how using record instead of class protect your code from what can be called "deserialization injection" 😌 19:35 Pattern matching 34:08 Using the record components in the pattern matching expression
@PietervandenHombergh
@PietervandenHombergh Год назад
Coverage in the switch can be achieved with an anon innner of the Shape in a unit test.
@PanMaciek
@PanMaciek Год назад
I love using pattern matching, but seeing how java is going to implement this I'm not sure it will feel great
@GavinFreeborn
@GavinFreeborn Год назад
This summarizes every functional feature java has added. Kinda sad but I guess it's at least there. Unfortunately a poor implementation means it's much harder to sell at work
@khalled95
@khalled95 Год назад
The main issues in java 17 that companies don't use or upgrade to it, most companies stick with java 8 or 11
@DavidBeaumont
@DavidBeaumont Год назад
I have a question about pattern matching on records (about 35:00). If you use "(Circle radius) -> radius * radius", what happens if you add a new component to Circle (e.g. a colour)? Now the record has a new canonical constructor. And worse, what if the property is the same type as the existing value (e.g. "double celcius"). Now I think that all the callers using pattern matching must update their code with a '_'? I guess (looking ahead) the owner of the type would be responsible for adding an explicit custom pattern to retain the old semantics, but this would be a manual thing you need to remember to do.
@TaranovskiAlex
@TaranovskiAlex 2 года назад
Thank you for the great talk!
@jamesschmames6416
@jamesschmames6416 Год назад
I thought it was bad form to throw exceptions in a constructor.
@patrickproctor3462
@patrickproctor3462 Год назад
It should be done judiciously. We use exception throws in constructors for user-provided data so we fail very loudly, very clearly, and in a way that tells our UI developers (and others) that they broke the rules of our API (without resorting to WSDLs which NO ONE wants to maintain).
@OMGitzBadCompany
@OMGitzBadCompany Год назад
It's far better than knowingly letting invalid objects pop into existence.
@IFraid
@IFraid Год назад
So, basically c#
@rsrini7
@rsrini7 Год назад
java becomes another scala
@pierre-jeanmartin5621
@pierre-jeanmartin5621 2 года назад
They should have picked a new language keyword instead of “instanceof”. Something like “ofpattern”. if ( object ofpattern Point(int x, int, y) ) // use x and y Or maybe it’s just me very not liking instanceof 😅
@DavidBeaumont
@DavidBeaumont Год назад
Adding new keywords is very hard since it's adding a new reserved word to the language specification and might make existing code stop compiling (e.g. if I have a variable or type called "ofpattern". I agree that "instanceof" is a bit unintuitive though, but it might be the pragmatic choice.
@pierre-jeanmartin5621
@pierre-jeanmartin5621 Год назад
@@DavidBeaumont i understand but it’s not like all modern IDE have a Replace in Files feature. A simple name like record was introduced but a non camel case keyword like « ofpattern » would be a problem 🤨🤔
@DavidBeaumont
@DavidBeaumont Год назад
@@pierre-jeanmartin5621 what about tools which process Java files or databases containing symbol information of binaries for debugging. There are a lot of potential ways new keywords can mess things up in hard to fix ways. Record is, I think, much easier because it's a new type identifier rather than a language keyword.
@MrKar18
@MrKar18 Год назад
​@@pierre-jeanmartin5621what about 10000 if libraries using? You can't modify existing libraries. Java has always been backward compatible. It can't be make or break as its enterprise's go to language.
@KangoV
@KangoV 7 месяцев назад
maybe if(object match Point(var x, var y)); ?
Далее
Wildest 10 SECONDS OF HIS LIFE 🤯 @TomIsted
00:14
Просмотров 1,4 млн
Это было очень близко...
00:10
Просмотров 1,6 млн
ТИПИЧНОЕ ПОВЕДЕНИЕ МАМЫ
00:21
Просмотров 1,4 млн
Ranking Java Features Added from Versions 8 to 21!
27:03
ORM, 20 years later by Gavin King
46:16
Просмотров 11 тыс.
Know your Java? By Venkat Subramaniam
2:39:20
Просмотров 29 тыс.
Know your Java? by Venkat Subramaniam
37:41
Просмотров 17 тыс.
Clean Code - Uncle Bob / Lesson 1
1:48:42
Просмотров 1,9 млн