diff --git a/slides.html b/slides.html new file mode 100644 index 0000000..7bf12bd --- /dev/null +++ b/slides.html @@ -0,0 +1,268 @@ +Una mirada funciona a Java 21
+

Una mirada 👀 funcional a Java 2️⃣1️⃣

+ +

Antonio Muñoz

+
#Commitconf 2024
+
+
+

¿Quien soy?

+
    +
  • Programo en Java desde Java 1.1.
  • +
  • Actualmente trabajo en https://clarity.ai como backender.
  • +
  • Mi primera charla en una conferencia.
  • +
  • +
+
#Commitconf 2024
+
+
+

Agenda 📆

+
    +
  • El largo camino a Java 21.
  • +
  • Tipos de datos algebraicos.
  • +
  • Ejemplos.
  • +
  • Futuro.
  • +
+
#Commitconf 2024
+
+
+

Java Release Cadence ☕

+
    +
  • Dos release al año.
  • +
  • Preview features.
  • +
  • They have a plan.
  • +
+
#Commitconf 2024
+
+
+

Switch expressions

+
    +
  • Incluido en Java 14.
  • +
  • Una nueva vida para switch.
  • +
  • Una gran mejora en general para el lenguage.
  • +
+
var value = switch (input) {
+    case "a" -> 1;
+    case "b" -> 2;
+    default -> 0;
+};
+
+
#Commitconf 2024
+
+
+

Records

+
    +
  • Incluido en Java 16.
  • +
  • Muy esperado por la comunidad.
  • +
  • Inmutables.
  • +
+
public record Movie(String title, int year, int duration) {
+
+}
+
+
#Commitconf 2024
+
+
+

Sealed classes and interfaces

+
    +
  • Incluido en Java 17.
  • +
  • Jerarquías de clases cerradas.
  • +
+
public sealed interface Shape {
+
+    record Square(int side) implements Shape {}
+    record Rectangle(int weight, int height) implements Shape {}
+    record Circle(int radious) implements Shape {}
+
+}
+
+
#Commitconf 2024
+
+
+

Pattern matching for switch

+
    +
  • Incluido en Java 21.
  • +
  • Exhaustiveness.
  • +
+
var result = switch (obj) {
+    case Integer i -> String.format("int %d", i);
+    case Long l    -> String.format("long %d", l);
+    case Double d  -> String.format("double %f", d);
+    case String s  -> String.format("String %s", s);
+    default        -> obj.toString();
+};
+
+
#Commitconf 2024
+
+
+

Record patterns

+
    +
  • Incluido en Java 21.
  • +
  • Deconstructores, nos permite acceder a los componentes de los objectos.
  • +
+
var area = switch (shape) {
+    case Square(var side) -> side * side;
+    case Rectangle(var weight, var height) -> weight * height;
+    case Circle(var radious) -> Math.PI * radious^2;
+}
+
+
#Commitconf 2024
+
+
+

Tipos de datos algebraicos

+
    +
  • AKA ADTs (algebraic data types)
  • +
  • Viene de las matemáticas.
  • +
  • Productos y sumas de tipos.
  • +
  • Recursivo.
  • +
+
#Commitconf 2024
+
+
+

Tipos de datos algebraicos (II)

+
    +
  • Podemos representarlos en Java.
  • +
  • Un record es un producto de tipos.
  • +
  • Un sealed interface es una suma de tipos.
  • +
+
public sealed interface Tree {
+
+    record Node(String value, Tree left, Tree right) implements Tree { }
+    record Leaf(String value) implements Tree {}
+
+} 
+
+
#Commitconf 2024
+
+
+

Tipos de datos algebraicos (III)

+
    +
  • Podemos representar Optional con ADTs
  • +
+
public sealed interface Optional<T> {
+
+    record Empty<T>() implements Optional<T> { }
+    record Present<T>(T value) implements Optional<T> {}
+
+} 
+
+
#Commitconf 2024
+
+
+

Ejemplo

+
    +
  • ¿Pero eso para qué me sirve?
  • +
  • Manejo de errores.
  • +
+
#Commitconf 2024
+
+
+

Próximamente ⌚

+
#Commitconf 2024
+
+
+

Unnamed variables and patterns

+
    +
  • Incluido en Java 22.
  • +
  • Mejora para el pattern matching.
  • +
  • Eliminar verbosidad.
  • +
+
var result = switch (obj) {
+    case Integer _ -> "int";
+    case Long _    -> "long";
+    case Double _  -> "double";
+    case String _  -> "string";
+    default        -> "other";
+};
+
+
#Commitconf 2024
+
+
+

Primitive types in patterns

+
    +
  • Preview en Java 23 (sep 2024).
  • +
+
var result = switch (obj) {
+    case int i -> String.format("int %d", i);
+    case long l    -> String.format("long %d", l);
+    case double d  -> String.format("double %f", d);
+    case String s  -> String.format("String %s", s);
+    default        -> obj.toString();
+};
+
+
#Commitconf 2024
+
+
+

Bola de cristal 🔮

+
#Commitconf 2024
+
+
+

Derived Record Creation

+
    +
  • Draft.
  • +
  • AKA withers.
  • +
+
Point newPoint = oldPoint with { 
+    x *= 2; 
+    y *= 2; 
+};
+
+
#Commitconf 2024
+
+
+

Member patterns

+
    +
  • Early work.
  • +
  • AKA deconstructors.
  • +
  • Mejora para pattern matching.
  • +
  • Cualquier clase.
  • +
+
#Commitconf 2024
+
+
+

¿Qué falta todavía?

+
    +
  • Tail recursion.
  • +
  • Soporte de tipos de datos primitivos en genericos.
  • +
+
#Commitconf 2024
+
+
+

¿Preguntas?

+
#Commitconf 2024
+
+
+

¡Gracias!

+ + +
#Commitconf 2024
+
+
+

JEPs

+ +
#Commitconf 2024
+
+
\ No newline at end of file diff --git a/slides.md b/slides.md index 91d85c0..a49345b 100644 --- a/slides.md +++ b/slides.md @@ -1,10 +1,11 @@ --- marp: true title: Una mirada funciona a Java 21 -theme: default +theme: gaia color: #fff footer: #Commitconf 2024 backgroundImage: url('https://cdn.wallpapersafari.com/97/99/MnWulT.jpg') +transition: fade-out --- # Una mirada :eyes: funcional a Java :two::one: @@ -194,7 +195,7 @@ # Primitive types in patterns -* Preview en Java 23. +* Preview en Java 23 (sep 2024). ```java var result = switch (obj) { @@ -239,9 +240,8 @@ # ¿Qué falta todavía? -* ADTs son recursivos. * Tail recursion. -* Soporte para tipos de datos primitivos para genericos. +* Soporte de tipos de datos primitivos en genericos. --- diff --git a/slides.pdf b/slides.pdf new file mode 100644 index 0000000..6ee73b0 --- /dev/null +++ b/slides.pdf Binary files differ