Kotlin
L → ∞
@
@selassiabdellah ngMorocco
What is Kotlin ?
An open source JVM targeted
language for JVM, Android & JS
Why JetBrains do create Kotlin?
IDEs for every language
Language that cut down the codebase
Concise language
Get ride for language issue NPE,..
Why JetBrains do create Kotlin?
IDEs for every language
Language that cut down the codebase
Concise language
Get ride for language issues NPE,..
The Kotlin Language
Single line function.
Everything is expression in K
Mark return from labels
Lambda compile down to Anonymous
class
The Kotlin Language
Auto cast/smart cast
By default vars/types can’t have a null
value
Elvis operator
The less side effect you have the more
correct your program is (immutability)
- Hadi Hariri
JavaScript support
All language features in Kotlin 1.1
Reflection for JavaScript is not available
Dynamic types (dynamic types to
interoperate with “native” JavaScript
code)
JavaScript support
Node.js and the browser Support
npm The Kotlin Standard Library is
available for use through npm)
SINGLE LINE FUNCTION
fun double(x: Int): Int = x * 2
SINGLE LINE FUNCTION
fun double(x: Int) = x * 2
Kotlin By Example @lastIndex
length - 1
lastIndex
Kotlin By Example @Nullable
/**
* Consumes the next line of text and returns it.
* Returns null if there are no more lines.
*/
function readUtf8Line() throw "Exception"
/**
* Consumes the next line of text and returns it.
* Returns null if there are no more lines.
*/
fun readUtf8Line(): String?
Kotlin By Example @Nothing
fun fail() {
throw RuntimeException("Something went wrong")
}
fun fail(): Nothing {
throw RuntimeException("Something went wrong")
}
Kotlin By Example @when
if (firstName.equals("Dad")) {
person.setTeam(programmers);
} else if (lastName.equals("Dihiansan")) {
person.setTeam(designers);
} else {
person.setTeam(others);
}
when {
firstName == "Dan" -> person.team = programmers
lastName == "Dihiansan" -> person.team = designers
else -> person.team = others
}
Kotlin By Example @when
switch (firstName) {
case "Dan": person.setTeam(programmers)
break;
case "Jay": person.setTeam(programmers)
break;
case "Jamie": person.setTeam(designers)
break;
default:
person.setTeam(others)
}
when (firstName) {
"Dan", "Jay" -> person.team = programmers
"Jamie" -> person.team = designers
else -> person.team = others
}
Kotlin By Example @let
if (message != null) {
System.out.println(message)
}
message?.let { println(it) }
Kotlin By Example @?:
if (people == null) {
people = new ArrayList();
}
return people ?: emptyArrayList()
if (people == null) {
people = new ArrayList();
}
return people ?: emptyArrayList()
Just an ε demo
Where do I begin ?
Kotlin.link — almost a complete list of links to
Kotlin projects, libraries and other resources
Kotlin Weekly — a weekly mailing list containing
latest notable news and articles
The Daily Kotlin — Daily Kotlin news and tips
QUESTIONS?
@selassiabdellah

Kotlin L → ∞

  • 1.
  • 3.
    What is Kotlin? An open source JVM targeted language for JVM, Android & JS
  • 4.
    Why JetBrains docreate Kotlin? IDEs for every language Language that cut down the codebase Concise language Get ride for language issue NPE,..
  • 6.
    Why JetBrains docreate Kotlin? IDEs for every language Language that cut down the codebase Concise language Get ride for language issues NPE,..
  • 7.
    The Kotlin Language Singleline function. Everything is expression in K Mark return from labels Lambda compile down to Anonymous class
  • 8.
    The Kotlin Language Autocast/smart cast By default vars/types can’t have a null value Elvis operator
  • 9.
    The less sideeffect you have the more correct your program is (immutability) - Hadi Hariri
  • 10.
    JavaScript support All languagefeatures in Kotlin 1.1 Reflection for JavaScript is not available Dynamic types (dynamic types to interoperate with “native” JavaScript code)
  • 11.
    JavaScript support Node.js andthe browser Support npm The Kotlin Standard Library is available for use through npm)
  • 12.
    SINGLE LINE FUNCTION fundouble(x: Int): Int = x * 2
  • 13.
    SINGLE LINE FUNCTION fundouble(x: Int) = x * 2
  • 14.
    Kotlin By Example@lastIndex length - 1 lastIndex
  • 15.
    Kotlin By Example@Nullable /** * Consumes the next line of text and returns it. * Returns null if there are no more lines. */ function readUtf8Line() throw "Exception" /** * Consumes the next line of text and returns it. * Returns null if there are no more lines. */ fun readUtf8Line(): String?
  • 16.
    Kotlin By Example@Nothing fun fail() { throw RuntimeException("Something went wrong") } fun fail(): Nothing { throw RuntimeException("Something went wrong") }
  • 17.
    Kotlin By Example@when if (firstName.equals("Dad")) { person.setTeam(programmers); } else if (lastName.equals("Dihiansan")) { person.setTeam(designers); } else { person.setTeam(others); } when { firstName == "Dan" -> person.team = programmers lastName == "Dihiansan" -> person.team = designers else -> person.team = others }
  • 18.
    Kotlin By Example@when switch (firstName) { case "Dan": person.setTeam(programmers) break; case "Jay": person.setTeam(programmers) break; case "Jamie": person.setTeam(designers) break; default: person.setTeam(others) } when (firstName) { "Dan", "Jay" -> person.team = programmers "Jamie" -> person.team = designers else -> person.team = others }
  • 19.
    Kotlin By Example@let if (message != null) { System.out.println(message) } message?.let { println(it) }
  • 20.
    Kotlin By Example@?: if (people == null) { people = new ArrayList(); } return people ?: emptyArrayList()
  • 21.
    if (people ==null) { people = new ArrayList(); } return people ?: emptyArrayList()
  • 22.
  • 23.
    Where do Ibegin ? Kotlin.link — almost a complete list of links to Kotlin projects, libraries and other resources Kotlin Weekly — a weekly mailing list containing latest notable news and articles The Daily Kotlin — Daily Kotlin news and tips
  • 24.

Editor's Notes

  • #2 Bonjour Tous le monde A prime abord je me présente je suis Abdellah SELASSI Expert Android et développeur full stack mobile. Aujourd’hui vous allez voir le magnifique langage Kotlin développé par JetBrains et qui le langage le plus préféré dans la communauté Android ainsi qu’il est officiellement reconnu par google
  • #3 Voici quelque société qui utilise Kotlin
  • #4 C’est quoi Kotlin ? C'est un nouveau langage de programmation ciblant la plate-forme Java et JavaScript. Kotlin est un langage dont le typage est statique qui vise la lisibilité du coup il est concise, pragmatique ainsi qu’il le langage a introduit un nouveau concept et qui est parmis c’est point fort : qui est l'interopérabilité avec Java et JavaScript. Il peut être utilisé presque partout où Java & JavaScript est utilisé aujourd'hui: pour le développement côté serveur, côté client, développement Android, et bien plus encore. Kotlin fonctionne très bien avec toutes les librairies et frameworks Java et JavaScript existants. Kotlin vient de l'industrie, pas du milieu académique. Ce qui dit qu’il résout les problèmes rencontrés aujourd’hui par les programmeurs. --- Statically typed programming language for the JVM, Android and the browser Target platforms : server-side, Android, JS, anywhere Java runs
  • #5 Les utilisateurs de Kotlin obtiennent encore plus: la sécurité nulle imposée par le compilateur L'approche des langues modernes, y compris Kotlin, consiste à convertir (NullPointerException) des erreurs d'exécution en erreurs de compilation. Via le support de la nullabilité dans les types du système, le compilateur peut détecter de nombreuses erreurs possibles pendant la compilation et réduire la possibilité d'avoir des exceptions lancées au moment de l'exécution ---- Kotlin users get even more: compiler-enforced null safety The approach of modern languages, including Kotlin, is to convert these problems (NPE) from runtime errors into compile-time errors. By supporting nullability as part of the type system, the compiler can detect many possible errors during compilation and reduce the possibility of having exceptions thrown at runtime
  • #7 Les utilisateurs de Kotlin obtiennent encore plus: la sécurité nulle imposée par le compilateur L'approche des langues modernes, y compris Kotlin, consiste à convertir (NullPointerException) des erreurs d'exécution en erreurs de compilation. Via le support de la nullabilité dans les types du système, le compilateur peut détecter de nombreuses erreurs possibles pendant la compilation et réduire la possibilité d'avoir des exceptions lancées au moment de l'exécution ---- Kotlin users get even more: compiler-enforced null safety The approach of modern languages, including Kotlin, is to convert these problems (NPE) from runtime errors into compile-time errors. By supporting nullability as part of the type system, the compiler can detect many possible errors during compilation and reduce the possibility of having exceptions thrown at runtime
  • #8  Single line function (function with no body) -> equal’s some value -> type inference -> ignore type return Everything is expression in K -> return expression directly Mark return from labels -> useful with lambda Lambda compile down to Anonymous class (AC) -> AC has ref to it’s parent (K handle this think like Java 8)
  • #13 Single line function (function with no body) -> equal’s some value -> type inference -> ignore type return Lorsqu'une fonction renvoie une seule expression, les accolades peuvent être omises et le corps de la fonction deviendra après le symbole = When a function returns a single expression, the curly braces can be omitted and the body is specified after a = symbol
  • #14 La déclaration explicite du type de retour est facultative lorsque cela peut être déduit par le compilateur -- Explicitly declaring the return type is optional when this can be inferred by the compiler
  • #17 The Nothing type : This function never returns
  • #20 ... // execute this block if not null