java8 experiment - normandy jug

Post on 22-Jan-2018

596 Views

Category:

Software

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Java 8 eXperiment(s)François SarradinNormandy JUG20 octobre 2015

WARNING!!!

françois sarradin• ippon technologies (ippon.fr)

• manager technique capitalisation

• extremist programmer, FP, agilité

• http://brownbaglunch.fr/

• twitter: @fsarradin

• blog: https://kerflyn.wordpress.com/

plan

1. héritage multiple

2. exception

3. pattern matching

et du live coding !!!

héritage multiple

objet = état + comportement

en java 8, on peut faire de l’héritage multiple de comportement

mais peut-on faire de l’héritage multiple d’état ?

un mail de Brian GoetzSubject: Re: From virtual extension methods to mixingFrom: Brian Goetz <…@oracle.com>Date: Mon, 9 Jul 2012 07:50:11 -0400Cc: lambda-dev@openjdk.java.netTo: François Sarradin <…@gmail.com>

Please don't encourage techniques like this. There are a zillion "clever" things you can do in Java, but shouldn't. We knew it wouldn’t be long before someone suggested this, and we can't stop you. But please, use your power for good, and not for evil. Teach people to do it right, not to abuse it.

But please, use your power for good, and not for evil.

Please don't encourage techniques like this.

un autre mail de Brian GoetzSubject: Re: From virtual extension methods to mixinsFrom: Brian Goetz <…@oracle.com>Date: Tue, 10 Jul 2012 19:51:55 -0400To: François Sarradin <…@gmail.com>

[…]

The bottom line is:

interfaces cannot be counted on to have identity.

Which is a good thing, but can bite the "clever" from behind :)

ce qu’il faut retenir

un mail de Brian GoetzSubject: Re: From virtual extension methods to mixingFrom: Brian Goetz <…@oracle.com>Date: Mon, 9 Jul 2012 07:50:11 -0400Cc: lambda-dev@openjdk.java.netTo: François Sarradin <…@gmail.com>

Please don't encourage techniques like this. There are a zillion "clever" things you can do in Java, but shouldn't. We knew it wouldn’t be long before someone suggested this, and we can't stop you. But please, use your power for good, and not for evil. Teach people to do it right, not to abuse it.

There are a zillion "clever" things you can do in Java, but

shouldn't.

exception

sun.misc.Unsafe est voué à disparaître ?

checked exception non déclarée

Field f = Unsafe.class.getDeclaredField("theUnsafe");f.setAccessible(true);Unsafe unsafe = (Unsafe) f.get(null);

// throw undeclared checked exceptionunsafe.throwException(new IOException());

alternative ?

ce qu’il faut retenir

limiter le nombre de sous-classes

public class Base { private Base() {}

public static class Class1 extends Base {} public static class Class2 extends Base {} // ...}

type checking

• limitation des sous-classes + generics => TDD

• TDD = type driven development

• ATTENTION !!! null interdit (checkstyle)

pyramide de test

UI

Intégration

Unitaire

Compilateur

pattern matching

Java 8 introduit la programmation fonctionnelle

peut-on tenter d’y introduire le pattern matching

pattern matching (scala)

myValue match { case "hello" => println("hello world") case i: Int => println("int: $i") case Add(a, b) => println("$a + $b = ${a + b}") case _ => println("what else!")}

ce qu’il faut retenir

dsl en javaFirstWord firstWord(T t) { return new FirstWord(t); }

class FirstWord { final T t; FirstWord(T t) { this.t = t; }

FirstWord repeat(T t0) { return new FirstWord(t + t0); } SecondWord secondWord(R r) { return new SecondWord(r); }

class SecondWord(R r) { final R r; SecondWord(R r) { this.r = r; }

S end() { return /* ... */; } }}

functional apis (beyond java 8)• fugue (https://bitbucket.org/atlassian/fugue)

• functional java (http://www.functionaljava.org/)

• totallylazy (http://totallylazy.com/)

• jOOλ (https://github.com/jOOQ/jOOL)

• javaslang (http://javaslang.com/)

• cyclops (https://github.com/aol/cyclops)

conclusion

• optimisation en java (ne pas trop avec les concepts)

• limiter le nombres de sous-classes

• type driven development

• dsl en java

KEEPCALMAND

THANKYOU

top related