KOTLINFlorian BELLOTTI
16/01/2018
Kotlin
Language de programmation :
• Orienté objet & fonctionnel

• Typage statique

• Inférence de type 

Développé par JetBrains (IntelliJ)
Multi-plateformes
AndroidJVM Browser Natif
Avantages
Tool-friendlyConcis Sûr Interoperable
Concis
Créer un objet avec getters, setters, equals(), hashCode(),
toString() et copy() en une ligne
Filtrer une liste avec une expression landba
Créer un singleton
data	class	Customer(val	name:	String,	val	email:	String,	val	company:	String)
val	positiveNumbers	=	list.filter	{	it	>	0	}
object	ThisIsASingleton	{	
				val	companyName:	String	=	"JetBrains"	
}
Sûr
Débarrassez-vous des NullPointerExceptions
Kotlin vous protège de l'utilisation de types « nullables »
Le compilateur vérifiera automatiquement le type pour vous
var	output:	String	
output	=	null			//	Compilation	error
val	name:	String?	=	null				//	Nullable	type	
println(name.length())						//	Compilation	error
fun	calculateTotal(obj:	Any)	{	
				if	(obj	is	Invoice)	
								obj.calculateTotal()	
}
Interoperable
Utilisez une bibliothèque existante sur la JVM
import	org.springframework.boot.SpringBootApplication	
@SpringBootApplication	
class	MyApp
import	kotlin.browser.window	
fun	onLoad()	{	
				window.document.body!!.innerHTML	+=	"<br/>Hello,	Kotlin!"	
}
Tool-friendly
Kotlin est développé par JetBrains et donc très bien intégré
dans leurs outils
Exemple
class	Task(	
val	id:	TaskId,	
val	name:	String,	
private	val	priority:	TaskPriority	=	NORMAL	
)	{	
fun	isImportant()	=	when	(priority)	{	
HIGH	->	true	
NORMAL,	LOW	->	false	
}	
fun	duplicate():	Task	{	
val	newName	=	"$name	(copy)"		
/*	…	*/	
}	
}	
Task(name	=	"$name	(copy)",	id	=	TaskId.random())
Autres avantages
Langage provenant de l’industrie et non d’académies
• plus proche des problématiques des développeurs 

Faible coût d’adoption
• conversion en 1 clic de Java à Kotlin

• facilement compréhensible

• 100 % compatible avec le Java
Ils l’utilisent
Application
principale
Invite à
utiliser Kotlin
Application
android
Application
Trello
android
Outils
internes
Support
pour Spring
Retour d’expérience
Utilisé pour le Backend depuis 6 mois
Avantages
• Très simple et rapide à prendre en main

• Très concis et reste lisible et compréhensible

• La sureté évite de nombreux bugs

• Accélère le développement

• Très bonne documentation

Inconvénients 

• Légèrement plus long à compiler

• Pas de « code coverage » sur sonar
Est ce que Kotlin peut
remplacer le Java pour
les développements
backend ?
OUI !
Aller plus loin
Documentation officielle
https://kotlinlang.org/docs/reference/
Developing Spring Boot applications with Kotlin, Sébastien
Deleuze

https://spring.io/blog/2016/02/15/developing-spring-boot-applications-with-kotlin

Kotling and Java: Where Do They Fit In?, Anthony Awuzie 

https://dzone.com/articles/kotlin-and-java-where-do-they-fit-in
Why Kotlin is my next programming language, Mike Hearn 

https://medium.com/@octskyward/why-kotlin-is-my-next-programming-language-c25c001e26e3
Why you should totally switch to Kotlin, Magnus Vinther 

https://medium.com/@magnus.chatt/why-you-should-totally-switch-to-kotlin-c7bbde9e10d5
@FlorianBellotti
contact@fbellotti.com
www.fbellotti.com

Présentation de kotlin