SlideShare a Scribd company logo
1 of 71
Download to read offline
Kotlin: forse è la volta buona
Jug Day - Trento 19/05/2018
Davide Cerbo
10+ years of experience
Full-stack
DevDay co-founder
I write code, I see people
Chi sono
Disclaimer
Here we have a lot of println, and some jokes.
My wife said that they aren’t funny.
C’era una volta OAK
It was 1992 and in Italy there
was a big scandal: Tangentopoli.
C’era una volta OAK Java
Borns in 1995
and now can
drink beers.
Il grande problema
Backward
compatibility
(The art of killing your app because the
environment evolves while you can’t)
JDK 1.0 (21 January 1996)
JDK 1.1 (19 February 1997)
J2SE 1.2 (8 December 1998)
J2SE 1.3 (8 May 2000)
J2SE 1.4 (6 February 2002)
J2SE 5.0 (30 September 2004)
Java SE 6 (11 December 2006)
Java SE 7 (28 July 2011)
Java SE 8 (18 March 2014)
Java SE 9 (26 September 2017)
Java Se 10 (20 March 2018)
JVM != Java
JAVA JVM
Machine code is not enought?
Assembly languages
Machine code
Logic languages
(Prolog)
Functional languages
(Haskell)
Procedural languages
(C / Pascal)
Object-oriented languages
(Java)
The Case for Kotlin and Ceylon by Russel Winder
https://www.youtube.com/watch?v=cFL_DDXBkJQ
Why Kotlin?
So, why not Scala?
Kotlin is a better Java while Scala is more powerful than Java, and
probably than Kotlin. But, Kotlin borns in the industry for the industry
and it evolves with the industry in mind, while Scala borns at the
university and it is adapted to the industry. Unfortunately, I work for
the industry.
https://agilewombat.com/2016/02/01/scala-vs-kotlin/
https://superkotlin.com/kotlin-vs-scala/
So, why not, another one time, Scala?
Scala can interact with Java at the library level, meaning that Java
programs can use Scala libraries (objects and functions) and Scala
libraries can use Java libraries (objects and methods). But Scala
and Java programs must be built as separate projects, with distinct
build chains. Kotlin is different because it integrates with Java
programs at the source level. You can mix Java and Kotlin source
files in the same projects with a single build chain.
(The joy of Kotlin - Pierre Yves Saumont)
Java
Kotlin
Kotlin is a statically-typed programming
language that runs on the Java Virtual Machine
and also can be compiled to JavaScript source
code or uses the LLVM compiler infrastructure.
https://dzone.com/articles/why-learn-kotlin-infographic
Predicatability not performance:https://www.youtube.com/watch?v=ExkNNsDn6Vg
Since 2010 (2012): KOTLIN!
100% interoperable
with Java ☕
~40% less lines of
code than Java
Easy to learn, if you
know Java
JetBrains
It’s safe
Apache 2 ⛺
PerformancePredictability
04 January 2017
Introducing Kotlin support
in Spring Framework 5.0
https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0
https://github.com/sdeleuze/spring-kotlin-deepdive
17 May 2017
Kotlin on Android. Now official
https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/
http://nilhcem.com/swift-is-like-kotlin/
https://blog.jetbrains.com/kotlin/category/native/
https://github.com/JetBrains/kotlin-native
31 March 2017
Kotlin / Native borns!
5 June 2017
kotlin-react borns!
https://github.com/JetBrains/kotlin-wrappers/commits/master/kotlin-react
https://github.com/JetBrains/create-react-kotlin-app
May 2018
ThoughtWorks suggests to adopt Kotlin in
its Technlogy Radar
https://www.thoughtworks.com/radar/languages-and-frameworks/kotlin
May
2017
Nov
2017
May
2018
TrialAsses Adopt
Var o Val
var serie = "B"
var a = "Salernitana will win Serie $serie"
val b = "Salernitana will win Serie $serie"
IMMUTABLE
Fun
fun main(args: Array<String>){
hello("Davide", "Salerno")
}
fun hello(name: String, city: String){
println("Hello $name from $city")
}
JVM != Java
class Hello {
fun sayHello(): String {
return "hello!"
}
}
public final class Hello {
// access flags 0x11
public final sayHello()Ljava/lang/String;
@Lorg/jetbrains/annotations/NotNull;() // invisible
L0
LINENUMBER 8 L0
LDC "hello!"
ARETURN
L1
LOCALVARIABLE this Ltotest/Hello; L0 L1 0
MAXSTACK = 1
MAXLOCALS = 1
// access flags 0x1
public <init>()V
L0
LINENUMBER 6 L0
ALOAD 0
INVOKESPECIAL java/lang/Object.<init> ()V
RETURN
L1
LOCALVARIABLE this L/Hello; L0 L1 0
MAXSTACK = 1
MAXLOCALS = 1
@Lkotlin/Metadata;(mv={1, 1, 1}, bv={1, 0, 2}, k=1,
d1={"u0000u0012nu0002u0018u0002nu0002u0010u0000nu0002
u0008u0002nu0002u0010u000enu0000u0018u00002u00020u00
01Bu0005u00a2u0006u0002u0010u0002Ju0006u0010u0003u001
au00020u0004u00a8u0006u0005", d2={"L/Hello;", "", "()V",
"sayHello", "", "production sources for module coroutine_main"})
// compiled from: Hello.kt
}
@Metadata(
mv = {1, 1, 7},
bv = {1, 0, 2},
k = 1,
d1 =
{"u0000u0012nu0002u0018u0002nu0002
u0005¢u0006u0002u0010u0002Ju0006u00
d2 = {"Ltotest/Hello;", "", "()V", "sayHello", "", "
)
public final class Hello {
@NotNull
public final String sayHello() {
return "hello!";
}
}
Compile Decompile
Tools > Kotlin > Show Kotlin Bytecode > Decompile
Fun fun functions
fun hello(name: String, city: String = "Salerno") = println("Hello $name from $city")
hello("Davide", "Salerno")
hello(name = "Davide")
hello(city = "Salerno", name = "Valentina")
fun Int.multilpy(x: Int): Int = this * x // 5.multilpy(10)
infix fun Int.multilpy(x: Int): Int = this * x // 5 multilpy 10
Also helps with refactoring!
E gli operatori?
data class Point(val x: Int, val y: Int) {
operator fun plus(a: Point) = Point(x + a.x, y + a.y)
}
operator fun Point.unaryMinus() = Point(-x, -y)
val point = Point(10, 20)
println(point + point + point) //Point(x=30, y=60)
println(-point) // Point(x=-10, y=-20)
Tailrec
● Recursion, in some language, can cause: StackOverflow!
● Reduce stack execution.
● Tailrec will resolve this issue only if the recursive call is the last one.
● It transforms your code in imperative code. Less readable, but more fast.
● Performance improvement
fun factorial(n: Long): Long = if (n <= 1L) n else n * factorial(n - 1)
tailrec fun factorial(n: Long, accumulator: Long = 1): Long = if (n <= 1L) accumulator
else factorial(n - 1, accumulator * n)
Tailrec cannot
applicable
“If” will return the verified condition value
Tailrec decompiled
public static final long factorial(long n, long accumulator) {
while(n > 1L) {
long var10000 = n - 1L;
accumulator *= n;
n = var10000;
}
return accumulator;
}
public static long factorial$default(long var0, long var2, int var4, Object
var5) {
if((var4 & 2) != 0) {
var2 = 1L;
}
return factorial(var0, var2);
}
}
public static final long factorial(long n, long accumulator) {
return n <= 1L?accumulator:factorial(n - 1L, accumulator * n);
}
public static long factorial$default(long var0, long var2, int var4, Object
var5) {
if((var4 & 2) != 0) {
var2 = 1L;
}
return factorial(var0, var2);
}
With
Tailrec
Without
Tailrec
StackOverflow
Tools > Kotlin > Show Kotlin Bytecode > Decompile
“If” is an expression, not a construct,
i.e. it returns a value.
Class
open class Person(val name: String) {
init { println("init…") }
open fun speak() { println("Hi $name!") }
infix fun and(o: Person) = "Hi ${o.name} & ${this.name}"
}
fun main(args: Array<String>) {
Person("Davide") and Person("Valentina")
val p = Person("Jack")
p.speak()
}
Class
class Customer(name: String) : Person(name) {
override fun speak() {
println("Welcome $name!")
}
}
class CustomerDavide : Person("Davide") {
override fun speak() {
println("Welcome $name!")
}
}
Equals, hashCode, toString e copy, nevermore!
data class User(val name: String, val age: Int)
val davide = User("Davide", 35)
val davideJunior = davide.copy(age=0)
fun main(args: Array<String>) {
val (name, age) = davide
println("$name $age years old")
}
deconstructing
Nothing is equal as appear
data class Point(val x: Int, val y: Int)
val a = Point(1, 2)
val b = Point(1, 2)
val c = a
println(a === b) // false
println(a == b) // true
println(a === c) // true
println(a == c) // true
Check the reference
.equals(...)
Lambda
fun main(args: Array<String>) {
arrayOf("Valentina", "Davide").forEach { println("Hello $it!") }
val ints =(1..3)
val logger = { msg: Any -> println("log $msg") }
ints.map { value -> value * 2 }.map { v -> logger(v) }
ints.map { it * 2 }.map { logger(it) }
}
Lambda
class Customer(val name: String) {
fun forEach(action: (char: Char) -> Unit) = name.forEach(action)
fun upperCaseAndConcat(callback: () -> String) = "${callback()} $name".toUpperCase()
}
fun main(args: Array<String>) {
val customer = Customer("Davide")
customer.forEach { println(it.toInt()) } //68 97 118 105 100 101
println(customer.upperCaseAndConcat { "Cerbo" }) //CERBO DAVIDE
}
The type with only one value: the Unit
object. This type corresponds to the void
type in Java.
Lambda Java -> Java 8 -> Kotlin
public class MapsTest {
private Map<String, Integer> scores = new HashMap<String, Integer>() {
{
put("Jack", 12);
put("Jill", 15);
put("Tom", 11);
put("Darla", 15);
put("TOM", 11);
put("Nick", 15);
put("Nancy", 11);
}
};
@Test
void maxNumberOfLetters() {
assertAll(
() -> assertEquals(4, (int) MapsK.maxNumberOfLetters(scores).get(12))
, () -> assertEquals(5, (int) MapsK.maxNumberOfLetters(scores).get(15))
, () -> assertEquals(5, (int) MapsK.maxNumberOfLetters(scores).get(11))
); } }
12: Jack
15: Jill. Darla, Nick
11: Tom, Tom, Nancy
12: 4
15: 5
11: 5
Lambda Java -> Java 8 -> Kotlin
public static Map<Integer, Integer> maxNumberOfLetters(Map<String, Integer> scores)
{
Map<Integer, Integer> byScores = new HashMap<>();
for (String name : scores.keySet())
{
int score = scores.get(name);
int maxLength = 0;
if (byScores.containsKey(score))
maxLength = byScores.get(score);
maxLength = maxLength < name.length() ? name.length() : maxLength;
byScores.put(score, maxLength);
}
return byScores;
}
Lambda Java -> Java 8 -> Kotlin
public static Map<Integer, Integer> maxNumberOfLetters(Map<String, Integer>
scores) {
return scores.keySet().stream()
.collect(groupingBy(scores::get,
collectingAndThen(maxBy(comparing(String::length)),
name -> name.orElse("").length())
));
}
Lambda Java -> Java 8 -> Kotlin
fun maxNumberOfLetters(scores: Map<String, Int>): Map<Int?, Int?> {
return scores
.keys
.groupBy(scores::get)
.mapValues {
it.value
.map(String::length)
.max()
}
}
https://medium.com/@davidecerbo/kotlin-vs-java-maps-6dcb6f4f21cd
Lambda & Function Label
fun forEachTest() {
val numbers = 1..100
numbers.forEach {
if (it == 25) {
return
}
println("index $it")
}
println("Hello")
}
fun forEachTest() {
val numbers = 1..100
numbers.forEach {
if (it == 25) {
return@forEach
}
println("index $it")
}
println("Hello")
}
Vs.
Tell me when, when?
fun describe(obj: Any): String = when (obj) {
1 -> "One"
"Hello" -> "Greeting"
is Long -> "Long"
!is String -> "Not a string"
else -> "Unknown"
}
describe(Person("davide"))
Null is safe!
var testA:String = "ciao"
var testB:String? = "ciao"
testB = null
println("a0 ${testA.length}")
println("b0 ${testB.length}")
// ^ Not safe! Compile time error! ^
println("b1 ${testB?.length}")
println("b2 ${testB!!.length}")
// ^ KotlinNullPointerException ^
// NPE Lovers
Null is safe!
val nullableList: List<Int?> = listOf(1, 2, null, 4)
val intList: List<Int> = nullableList.filterNotNull() // [1, 2, 4]
val aInt: Int? = b as? Int
// If b is null, normally we will have a NullPointerException, while if the type is
different we will have a ClassCastExeption. Using “as?” we haven’t an exception,
we will have a null value assigned to the aInt value.
Null is safe!
data class Person(val name: String, val age: Int?)
val person:Person? = Person("Jack", 1)
if (person?.age != null) {
println("The person is aged ${person?.age}")
}
//oppure
person?.age?.let {
println("The person is aged $it")
}
?:
Elvis operatorIt is the replacement to “Optional.getOrElse” in Java
val davide = Person(testA)
val elvis = Person(testB ?: "Elvis")
println(jack.name)
Kotlin forces you to handle it or to take full
responsibility.
Companion object
● No static members.
● Has access to private level method and properties of the main object.
● Companion objects can implements interfaces.
interface Factory<T> {
fun create(): T
}
class MyClass {
companion object : Factory<MyClass> {
@JvmStatic //converts to real static method
override fun create(): MyClass = MyClass()
}
}
Visibility Modifiers
private - means visible inside this class only (including
all its members);
protected — same as private + visible in subclasses too;
Override protected method are still protected.
internal — any client inside this module who sees the
declaring class sees its internal members. A module is a set
of Kotlin files compiled together;
public — any client who sees the declaring class sees its
public members. (Default)
Exception
Kotlin does not have checked exceptions
throw is an expression
val s = person.name ?: throw
IllegalArgumentException("Name required")
Property: Get & Set
class Strange(var value: Long) {
var strangeValue: Long
get() = value * 2
set(value){
if(value > 5) this.value = value
}
}
fun main(args: Array<String>) {
val customer = Strange(10)
println(customer.strangeValue) //20
customer.strangeValue = 3
println(customer.strangeValue) //20
customer.strangeValue = 6
println(customer.strangeValue) //12
}
Delegated properties: why me?
class Delegate {
operator fun getValue(thisRef: Any?, property: KProperty<*>): String {
return "$thisRef, thank you for delegating '${property.name}' to me!"
}
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) {
println("$value has been assigned to '${property.name} in $thisRef.'")
}
}
class Example {
var p: String by Delegate()
}
Delegated properties: the lazy & the observable
val lazyValue: String by lazy {
println("computed!")
"Hello"
}
fun main(args: Array<String>) {
println(lazyValue)
println(lazyValue)
}
class User {
var n: String by Delegates.observable("empty") {
prop, old, new -> println("$old -> $new")
}
}
fun main(args: Array<String>) {
val user = User()
user.n = "first"
user.n = "second"
}
Coroutine
Coroutine ⋍ light-weight thread
● They are like threads, they run in parallel, wait for each other and they communicate.
● They are cheap, we can create many of those without having performance issues.
● They are executed in a thread pool.
● A thread can handle more than one coroutine.
● Thread became free until a coroutine is in waiting state. When the coroutine will return active,
it doesn’t get the old thread, but it will use a free thread in the pool.
https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md
https://proandroiddev.com/approaching-kotlin-coroutines-an-extensive-feature-concurrent-programming-in-kotlin-eaaa19b003d2
Coroutine is humble
fun main(args: Array<String>) = runBlocking {
val jobs = List(100_000) {
launch {
delay(1000L)
print(".")
}
}
jobs.forEach { it.join() }
}
fun main(args: Array<String>) {
val jobs = List(100_000) {
thread(start = true) {
Thread.sleep(1000L)
print(".")
}
}
jobs.forEach { it.join() }
}
OUT OF MEMORY!!!
Coroutine: suspend, async / await
fun main(args: Array<String>) = runBlocking<Unit> {
val time = measureTimeMillis {
val one = doSomethingUsefulOne()
val two = doSomethingUsefulTwo()
println("The answer is ${one + two}")
}
println("Completed in $time ms")
}
suspend fun doSomethingUsefulOne(): Int {
delay(1000L)
return 13
}
suspend fun doSomethingUsefulTwo(): Int {
delay(1000L)
return 29
}
fun main(args: Array<String>) = runBlocking<Unit> {
val time = measureTimeMillis {
val one = async { doSomethingUsefulOne() }
val two = async { doSomethingUsefulTwo() }
println("The answer is ${one.await() + two.await()}")
}
println("Completed in $time ms")
}
suspend fun doSomethingUsefulOne(): Int {
delay(1000L)
return 13
}
suspend fun doSomethingUsefulTwo(): Int {
delay(1000L)
return 29
}
~2 sec.
~1 sec.
Coroutine is the basement
Coroutine
Actors
Communication
Sequence
Process
?
Now is the time to remember that Kotlin is good
because the trade-off between synthesis and
readable code is really good.
Automatic restart
Webapp: Gradle
buildscript {
...
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlinVersion"
}
}
...
apply plugin: "kotlin-jpa"
group = 'it.devday'
version = '0.0.1-SNAPSHOT'
...
}
JPA need an empty constructor in some entities,
and Kotlin objects don’t have. To solve this issue
we can use this plugin that will create an empty
constructor in any object, without any change to
our codebase.
Webapp: Domain & Repository
import it.devday.kotlincodemotion.domain.Contact
import org.springframework.data....JpaRepository
interface ItemRepository: JpaRepository<Item, Long>
import javax.persistence.Entity
import javax.persistence.GeneratedValue
import javax.persistence.Id
@Entity
data class Item(
@Id @GeneratedValue
val id: Long,
val description: String,
val vat: Double,
val price: Double,
val quantity: Double)
Webapp: Domain & Repository
@Embeddable
data class Price(val amount: Double) {
operator fun plus(a: Price) = a.amount + this.amount
operator fun rem(a: ValueAddedTax) =
this.amount * (100 + a.percentage) / 100
}
@Embeddable
data class Quantity(val value: Double)
@Embeddable
data class ValueAddedTax(val percentage: Double)
@Entity data class Item(
@Id @GeneratedValue
val id: Long, val description: String,
@Embedded val vat: ValueAddedTax,
@Embedded val price: Price,
@Embedded val quantity: Quantity) {
val grossPrice: Double
get() = this.price % this.vat
val total: Double
get() = this.grossPrice * quantity.value
}
Webapp: Resource 1/2
@RestController
@RequestMapping("/items")
class ItemResource(val repository: ItemRepository) {
@GetMapping //curl -XGET http://localhost:8080/items
fun getAll() = repository.findAll()
@GetMapping("/{id}") //curl -XGET http://localhost:8080/items/1
fun getAll(@PathVariable id: Long) = repository.findById(id)
Webapp: Resource 2/2
@PostMapping //curl -XPOST http://localhost:8080/items -H 'Content-Type: application/json' -d
'{"description":"Kotlin in action", "vat":{"percentage":10}, "price":{"amount":1.5}, "quantity":{"value":"10"}}'
fun insert(@RequestBody item: Item) = repository.save(item)
@DeleteMapping("/{id}") //curl -XDELETE http://localhost:8080/items/1
fun delete(@PathVariable id: Long) {
val item = repository.findById(id).unwrap()
item?.let { repository.delete(item) }
}
}
wait...unwrap() doesn’t exist on Optional class
Webapp: Application
@SpringBootApplication
class KotlinApplication
fun <T> Optional<T>.unwrap(): T? = orElse(null)
fun main(args: Array<String>) {
runApplication<KotlinApplication>(*args)
}
unwrap()!
array is passed element by element, it is used with vararg arguments
public inline fun <reified T : kotlin.Any> runApplication(vararg args: kotlin.String)
The generic type will be available in the method. Wow!
Webapp: Where is my Repository?
@RestController
@RequestMapping("/items")
class ItemResource() {
@GetMapping //curl -XGET http://localhost:8080/items
fun getAll() = Item.findAll()
@GetMapping("/{id}") //curl -XGET http://localhost:8080/items/1
fun getAll(@PathVariable id: Long) = Item.findById(id)
…...
Webapp: Domain & Repository Dao
@Entity data class Item(….) {
….
companion object : Dao<Item, Long>
}
Why this approach? http://mavi.logdown.com/posts/5771422
interface Dao<T, K>
inline fun <reified T : Any, K> Dao<T, K>.findById(id: K):
T = Db.exec { em -> em.find(T::class.java, id) } as T
inline fun <reified T : Any, K> Dao<T, K>.save(item: T):
Unit = Db.exec { em -> tx(em) { em.persist(item) } } as
Unit
...
….
fun tx(em: EntityManager, c: () -> Any): Any {
try {
em.transaction.begin()
val result = c()
em.transaction.commit()
return result
} finally {
em.close()
}
}
Webapp: Domain & Repository Dao
@Component
object Db : ApplicationContextAware {
var ac: ApplicationContext? = null
override fun setApplicationContext(applicationContext: ApplicationContext) {
ac = applicationContext!!
}
fun exec(callback: (em: EntityManager) -> Any): Any {
return callback(ac!!.getBean(EntityManagerFactory::class.java).createEntityManager())
} }
Webapp: Domain & Repository Dao
? ? ?
@davide_cerbo
@devdayit
http://slack.devday.it
http://medium.com/@davidecerbo
Everything is here:
https://github.com/jesty/kotlin-fossavotabona
Books!
Useful resources
https://kotlinlang.org/docs/reference/
https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0
https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/
https://dev.to/lovis/gang-of-four-patterns-in-kotlin
https://github.com/volodymyrprokopyuk/kotlin-sdp
https://github.com/gradle/gradle-script-kotlin
https://speakerdeck.com/sdeleuze/functional-web-applications-with-spring-and-kotlin
https://kotlinlang.org/docs/tutorials/httpservlets.html
http://thetechnocafe.com/more-about-functions-in-kotlin/
https://nklmish.wordpress.com/2017/10/22/deprecated-in-kotlin/
https://kotlinlang.org/docs/tutorials/command-line.html
https://agilewombat.com/2016/02/01/scala-vs-kotlin/
https://superkotlin.com/kotlin-vs-scala/
https://kotlinlang.org/docs/reference/type-safe-builders.html

More Related Content

What's hot

Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in JavaDoug Hawkins
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyDavid Gómez García
 
The Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaThe Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaVasil Remeniuk
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performanceintelliyole
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)intelliyole
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsBartosz Kosarzycki
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.JustSystems Corporation
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!José Paumard
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersBartosz Kosarzycki
 
Innovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and MonitoringInnovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and MonitoringCary Millsap
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2José Paumard
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Arnaud Giuliani
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Arnaud Giuliani
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsJussi Pohjolainen
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engineDuoyi Wu
 
Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...DroidConTLV
 

What's hot (19)

Concurrency Concepts in Java
Concurrency Concepts in JavaConcurrency Concepts in Java
Concurrency Concepts in Java
 
Leveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results AsynchrhonouslyLeveraging Completable Futures to handle your query results Asynchrhonously
Leveraging Completable Futures to handle your query results Asynchrhonously
 
The Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana IsakovaThe Kotlin Programming Language, Svetlana Isakova
The Kotlin Programming Language, Svetlana Isakova
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
 
Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)Feel of Kotlin (Berlin JUG 16 Apr 2015)
Feel of Kotlin (Berlin JUG 16 Apr 2015)
 
Kotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projectsKotlin Developer Starter in Android projects
Kotlin Developer Starter in Android projects
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.Kotlin is charming; The reasons Java engineers should start Kotlin.
Kotlin is charming; The reasons Java engineers should start Kotlin.
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
Kotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developersKotlin advanced - language reference for android developers
Kotlin advanced - language reference for android developers
 
Innovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and MonitoringInnovative Specifications for Better Performance Logging and Monitoring
Innovative Specifications for Better Performance Logging and Monitoring
 
Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2Lambdas and Streams Master Class Part 2
Lambdas and Streams Master Class Part 2
 
Comparing JVM languages
Comparing JVM languagesComparing JVM languages
Comparing JVM languages
 
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
Javantura v2 - All Together Now - making Groovy and Scala sing together - Din...
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Qt Memory Management & Signal and Slots
Qt Memory Management & Signal and SlotsQt Memory Management & Signal and Slots
Qt Memory Management & Signal and Slots
 
Virtual machine and javascript engine
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...Connecting your phone and home with firebase and android things - James Cogga...
Connecting your phone and home with firebase and android things - James Cogga...
 

Similar to Kotlin: forse è la volta buona (Trento)

Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Codemotion
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right timeDavide Cerbo
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)Pavlo Baron
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Mohamed Nabil, MSc.
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for KotlinTechMagic
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of androidDJ Rausch
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)David de Boer
 
JavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development ExperiencesJavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development ExperiencesPeter Pilgrim
 
Kotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKirill Rozov
 
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Naresha K
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesNaresha K
 
BOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala appsBOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala appsPeter Pilgrim
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?Squareboat
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyMobileAcademy
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with AndroidKurt Renzo Acosta
 

Similar to Kotlin: forse è la volta buona (Trento) (20)

Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017 Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
Davide Cerbo - Kotlin: forse è la volta buona - Codemotion Milan 2017
 
Kotlin: maybe it's the right time
Kotlin: maybe it's the right timeKotlin: maybe it's the right time
Kotlin: maybe it's the right time
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Kotlin for Android Developers - 3
Kotlin for Android Developers - 3Kotlin for Android Developers - 3
Kotlin for Android Developers - 3
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Kotlin – the future of android
Kotlin – the future of androidKotlin – the future of android
Kotlin – the future of android
 
Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)Being functional in PHP (PHPDay Italy 2016)
Being functional in PHP (PHPDay Italy 2016)
 
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter PilgrimJavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
JavaCro'14 - Scala and Java EE 7 Development Experiences – Peter Pilgrim
 
JavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development ExperiencesJavaCro 2014 Scala and Java EE 7 Development Experiences
JavaCro 2014 Scala and Java EE 7 Development Experiences
 
Kotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platformsKotlin 1.2: Sharing code between platforms
Kotlin 1.2: Sharing code between platforms
 
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
Effective Java with Groovy & Kotlin How Languages Influence Adoption of Good ...
 
Effective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good PracticesEffective Java with Groovy - How Language Influences Adoption of Good Practices
Effective Java with Groovy - How Language Influences Adoption of Good Practices
 
BOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala appsBOF2644 Developing Java EE 7 Scala apps
BOF2644 Developing Java EE 7 Scala apps
 
What’s new in Kotlin?
What’s new in Kotlin?What’s new in Kotlin?
What’s new in Kotlin?
 
Kotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRreadyKotlin for Android - Vali Iorgu - mRready
Kotlin for Android - Vali Iorgu - mRready
 
Building Mobile Apps with Android
Building Mobile Apps with AndroidBuilding Mobile Apps with Android
Building Mobile Apps with Android
 
Java
JavaJava
Java
 

More from Davide Cerbo

From 0 to React with ES6 and Tests
From 0 to React with ES6 and TestsFrom 0 to React with ES6 and Tests
From 0 to React with ES6 and TestsDavide Cerbo
 
Kotlin: foss' a vota bona (could be the right time)
Kotlin: foss' a vota bona (could be the right time)Kotlin: foss' a vota bona (could be the right time)
Kotlin: foss' a vota bona (could be the right time)Davide Cerbo
 
Il web intelligente
Il web intelligenteIl web intelligente
Il web intelligenteDavide Cerbo
 
Working between the clouds (versione completa)
Working between the clouds (versione completa)Working between the clouds (versione completa)
Working between the clouds (versione completa)Davide Cerbo
 
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...Davide Cerbo
 
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the cloudsDavide Cerbo
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Davide Cerbo
 
Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Davide Cerbo
 

More from Davide Cerbo (10)

From 0 to React with ES6 and Tests
From 0 to React with ES6 and TestsFrom 0 to React with ES6 and Tests
From 0 to React with ES6 and Tests
 
Kotlin: foss' a vota bona (could be the right time)
Kotlin: foss' a vota bona (could be the right time)Kotlin: foss' a vota bona (could be the right time)
Kotlin: foss' a vota bona (could be the right time)
 
Di cosa parlano?
Di cosa parlano?Di cosa parlano?
Di cosa parlano?
 
Adesso In Onda
Adesso In OndaAdesso In Onda
Adesso In Onda
 
Il web intelligente
Il web intelligenteIl web intelligente
Il web intelligente
 
Working between the clouds (versione completa)
Working between the clouds (versione completa)Working between the clouds (versione completa)
Working between the clouds (versione completa)
 
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
The Hitchhiker's Guide to testable code: semplici regole per scrivere codice ...
 
Working between the clouds
Working between the cloudsWorking between the clouds
Working between the clouds
 
Non Conventional Android Programming (English)
Non Conventional Android Programming (English)Non Conventional Android Programming (English)
Non Conventional Android Programming (English)
 
Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)Non Conventional Android Programming (Italiano)
Non Conventional Android Programming (Italiano)
 

Recently uploaded

Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 

Recently uploaded (20)

Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 

Kotlin: forse è la volta buona (Trento)

  • 1. Kotlin: forse è la volta buona Jug Day - Trento 19/05/2018
  • 2. Davide Cerbo 10+ years of experience Full-stack DevDay co-founder I write code, I see people Chi sono
  • 3. Disclaimer Here we have a lot of println, and some jokes. My wife said that they aren’t funny.
  • 4. C’era una volta OAK It was 1992 and in Italy there was a big scandal: Tangentopoli.
  • 5. C’era una volta OAK Java Borns in 1995 and now can drink beers.
  • 6. Il grande problema Backward compatibility (The art of killing your app because the environment evolves while you can’t) JDK 1.0 (21 January 1996) JDK 1.1 (19 February 1997) J2SE 1.2 (8 December 1998) J2SE 1.3 (8 May 2000) J2SE 1.4 (6 February 2002) J2SE 5.0 (30 September 2004) Java SE 6 (11 December 2006) Java SE 7 (28 July 2011) Java SE 8 (18 March 2014) Java SE 9 (26 September 2017) Java Se 10 (20 March 2018)
  • 8. Machine code is not enought? Assembly languages Machine code Logic languages (Prolog) Functional languages (Haskell) Procedural languages (C / Pascal) Object-oriented languages (Java) The Case for Kotlin and Ceylon by Russel Winder https://www.youtube.com/watch?v=cFL_DDXBkJQ
  • 10. So, why not Scala? Kotlin is a better Java while Scala is more powerful than Java, and probably than Kotlin. But, Kotlin borns in the industry for the industry and it evolves with the industry in mind, while Scala borns at the university and it is adapted to the industry. Unfortunately, I work for the industry. https://agilewombat.com/2016/02/01/scala-vs-kotlin/ https://superkotlin.com/kotlin-vs-scala/
  • 11. So, why not, another one time, Scala? Scala can interact with Java at the library level, meaning that Java programs can use Scala libraries (objects and functions) and Scala libraries can use Java libraries (objects and methods). But Scala and Java programs must be built as separate projects, with distinct build chains. Kotlin is different because it integrates with Java programs at the source level. You can mix Java and Kotlin source files in the same projects with a single build chain. (The joy of Kotlin - Pierre Yves Saumont)
  • 13. Kotlin is a statically-typed programming language that runs on the Java Virtual Machine and also can be compiled to JavaScript source code or uses the LLVM compiler infrastructure.
  • 14. https://dzone.com/articles/why-learn-kotlin-infographic Predicatability not performance:https://www.youtube.com/watch?v=ExkNNsDn6Vg Since 2010 (2012): KOTLIN! 100% interoperable with Java ☕ ~40% less lines of code than Java Easy to learn, if you know Java JetBrains It’s safe Apache 2 ⛺ PerformancePredictability
  • 15. 04 January 2017 Introducing Kotlin support in Spring Framework 5.0 https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0 https://github.com/sdeleuze/spring-kotlin-deepdive
  • 16. 17 May 2017 Kotlin on Android. Now official https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/ http://nilhcem.com/swift-is-like-kotlin/
  • 18. 5 June 2017 kotlin-react borns! https://github.com/JetBrains/kotlin-wrappers/commits/master/kotlin-react https://github.com/JetBrains/create-react-kotlin-app
  • 19. May 2018 ThoughtWorks suggests to adopt Kotlin in its Technlogy Radar https://www.thoughtworks.com/radar/languages-and-frameworks/kotlin May 2017 Nov 2017 May 2018 TrialAsses Adopt
  • 20.
  • 21. Var o Val var serie = "B" var a = "Salernitana will win Serie $serie" val b = "Salernitana will win Serie $serie" IMMUTABLE
  • 22. Fun fun main(args: Array<String>){ hello("Davide", "Salerno") } fun hello(name: String, city: String){ println("Hello $name from $city") }
  • 23. JVM != Java class Hello { fun sayHello(): String { return "hello!" } } public final class Hello { // access flags 0x11 public final sayHello()Ljava/lang/String; @Lorg/jetbrains/annotations/NotNull;() // invisible L0 LINENUMBER 8 L0 LDC "hello!" ARETURN L1 LOCALVARIABLE this Ltotest/Hello; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 // access flags 0x1 public <init>()V L0 LINENUMBER 6 L0 ALOAD 0 INVOKESPECIAL java/lang/Object.<init> ()V RETURN L1 LOCALVARIABLE this L/Hello; L0 L1 0 MAXSTACK = 1 MAXLOCALS = 1 @Lkotlin/Metadata;(mv={1, 1, 1}, bv={1, 0, 2}, k=1, d1={"u0000u0012nu0002u0018u0002nu0002u0010u0000nu0002 u0008u0002nu0002u0010u000enu0000u0018u00002u00020u00 01Bu0005u00a2u0006u0002u0010u0002Ju0006u0010u0003u001 au00020u0004u00a8u0006u0005", d2={"L/Hello;", "", "()V", "sayHello", "", "production sources for module coroutine_main"}) // compiled from: Hello.kt } @Metadata( mv = {1, 1, 7}, bv = {1, 0, 2}, k = 1, d1 = {"u0000u0012nu0002u0018u0002nu0002 u0005¢u0006u0002u0010u0002Ju0006u00 d2 = {"Ltotest/Hello;", "", "()V", "sayHello", "", " ) public final class Hello { @NotNull public final String sayHello() { return "hello!"; } } Compile Decompile Tools > Kotlin > Show Kotlin Bytecode > Decompile
  • 24. Fun fun functions fun hello(name: String, city: String = "Salerno") = println("Hello $name from $city") hello("Davide", "Salerno") hello(name = "Davide") hello(city = "Salerno", name = "Valentina") fun Int.multilpy(x: Int): Int = this * x // 5.multilpy(10) infix fun Int.multilpy(x: Int): Int = this * x // 5 multilpy 10 Also helps with refactoring!
  • 25. E gli operatori? data class Point(val x: Int, val y: Int) { operator fun plus(a: Point) = Point(x + a.x, y + a.y) } operator fun Point.unaryMinus() = Point(-x, -y) val point = Point(10, 20) println(point + point + point) //Point(x=30, y=60) println(-point) // Point(x=-10, y=-20)
  • 26. Tailrec ● Recursion, in some language, can cause: StackOverflow! ● Reduce stack execution. ● Tailrec will resolve this issue only if the recursive call is the last one. ● It transforms your code in imperative code. Less readable, but more fast. ● Performance improvement fun factorial(n: Long): Long = if (n <= 1L) n else n * factorial(n - 1) tailrec fun factorial(n: Long, accumulator: Long = 1): Long = if (n <= 1L) accumulator else factorial(n - 1, accumulator * n) Tailrec cannot applicable “If” will return the verified condition value
  • 27. Tailrec decompiled public static final long factorial(long n, long accumulator) { while(n > 1L) { long var10000 = n - 1L; accumulator *= n; n = var10000; } return accumulator; } public static long factorial$default(long var0, long var2, int var4, Object var5) { if((var4 & 2) != 0) { var2 = 1L; } return factorial(var0, var2); } } public static final long factorial(long n, long accumulator) { return n <= 1L?accumulator:factorial(n - 1L, accumulator * n); } public static long factorial$default(long var0, long var2, int var4, Object var5) { if((var4 & 2) != 0) { var2 = 1L; } return factorial(var0, var2); } With Tailrec Without Tailrec StackOverflow Tools > Kotlin > Show Kotlin Bytecode > Decompile
  • 28. “If” is an expression, not a construct, i.e. it returns a value.
  • 29. Class open class Person(val name: String) { init { println("init…") } open fun speak() { println("Hi $name!") } infix fun and(o: Person) = "Hi ${o.name} & ${this.name}" } fun main(args: Array<String>) { Person("Davide") and Person("Valentina") val p = Person("Jack") p.speak() }
  • 30. Class class Customer(name: String) : Person(name) { override fun speak() { println("Welcome $name!") } } class CustomerDavide : Person("Davide") { override fun speak() { println("Welcome $name!") } }
  • 31. Equals, hashCode, toString e copy, nevermore! data class User(val name: String, val age: Int) val davide = User("Davide", 35) val davideJunior = davide.copy(age=0) fun main(args: Array<String>) { val (name, age) = davide println("$name $age years old") } deconstructing
  • 32. Nothing is equal as appear data class Point(val x: Int, val y: Int) val a = Point(1, 2) val b = Point(1, 2) val c = a println(a === b) // false println(a == b) // true println(a === c) // true println(a == c) // true Check the reference .equals(...)
  • 33. Lambda fun main(args: Array<String>) { arrayOf("Valentina", "Davide").forEach { println("Hello $it!") } val ints =(1..3) val logger = { msg: Any -> println("log $msg") } ints.map { value -> value * 2 }.map { v -> logger(v) } ints.map { it * 2 }.map { logger(it) } }
  • 34. Lambda class Customer(val name: String) { fun forEach(action: (char: Char) -> Unit) = name.forEach(action) fun upperCaseAndConcat(callback: () -> String) = "${callback()} $name".toUpperCase() } fun main(args: Array<String>) { val customer = Customer("Davide") customer.forEach { println(it.toInt()) } //68 97 118 105 100 101 println(customer.upperCaseAndConcat { "Cerbo" }) //CERBO DAVIDE } The type with only one value: the Unit object. This type corresponds to the void type in Java.
  • 35. Lambda Java -> Java 8 -> Kotlin public class MapsTest { private Map<String, Integer> scores = new HashMap<String, Integer>() { { put("Jack", 12); put("Jill", 15); put("Tom", 11); put("Darla", 15); put("TOM", 11); put("Nick", 15); put("Nancy", 11); } }; @Test void maxNumberOfLetters() { assertAll( () -> assertEquals(4, (int) MapsK.maxNumberOfLetters(scores).get(12)) , () -> assertEquals(5, (int) MapsK.maxNumberOfLetters(scores).get(15)) , () -> assertEquals(5, (int) MapsK.maxNumberOfLetters(scores).get(11)) ); } } 12: Jack 15: Jill. Darla, Nick 11: Tom, Tom, Nancy 12: 4 15: 5 11: 5
  • 36. Lambda Java -> Java 8 -> Kotlin public static Map<Integer, Integer> maxNumberOfLetters(Map<String, Integer> scores) { Map<Integer, Integer> byScores = new HashMap<>(); for (String name : scores.keySet()) { int score = scores.get(name); int maxLength = 0; if (byScores.containsKey(score)) maxLength = byScores.get(score); maxLength = maxLength < name.length() ? name.length() : maxLength; byScores.put(score, maxLength); } return byScores; }
  • 37. Lambda Java -> Java 8 -> Kotlin public static Map<Integer, Integer> maxNumberOfLetters(Map<String, Integer> scores) { return scores.keySet().stream() .collect(groupingBy(scores::get, collectingAndThen(maxBy(comparing(String::length)), name -> name.orElse("").length()) )); }
  • 38. Lambda Java -> Java 8 -> Kotlin fun maxNumberOfLetters(scores: Map<String, Int>): Map<Int?, Int?> { return scores .keys .groupBy(scores::get) .mapValues { it.value .map(String::length) .max() } } https://medium.com/@davidecerbo/kotlin-vs-java-maps-6dcb6f4f21cd
  • 39. Lambda & Function Label fun forEachTest() { val numbers = 1..100 numbers.forEach { if (it == 25) { return } println("index $it") } println("Hello") } fun forEachTest() { val numbers = 1..100 numbers.forEach { if (it == 25) { return@forEach } println("index $it") } println("Hello") } Vs.
  • 40. Tell me when, when? fun describe(obj: Any): String = when (obj) { 1 -> "One" "Hello" -> "Greeting" is Long -> "Long" !is String -> "Not a string" else -> "Unknown" } describe(Person("davide"))
  • 41. Null is safe! var testA:String = "ciao" var testB:String? = "ciao" testB = null println("a0 ${testA.length}") println("b0 ${testB.length}") // ^ Not safe! Compile time error! ^ println("b1 ${testB?.length}") println("b2 ${testB!!.length}") // ^ KotlinNullPointerException ^ // NPE Lovers
  • 42. Null is safe! val nullableList: List<Int?> = listOf(1, 2, null, 4) val intList: List<Int> = nullableList.filterNotNull() // [1, 2, 4] val aInt: Int? = b as? Int // If b is null, normally we will have a NullPointerException, while if the type is different we will have a ClassCastExeption. Using “as?” we haven’t an exception, we will have a null value assigned to the aInt value.
  • 43. Null is safe! data class Person(val name: String, val age: Int?) val person:Person? = Person("Jack", 1) if (person?.age != null) { println("The person is aged ${person?.age}") } //oppure person?.age?.let { println("The person is aged $it") }
  • 44. ?: Elvis operatorIt is the replacement to “Optional.getOrElse” in Java val davide = Person(testA) val elvis = Person(testB ?: "Elvis") println(jack.name)
  • 45. Kotlin forces you to handle it or to take full responsibility.
  • 46. Companion object ● No static members. ● Has access to private level method and properties of the main object. ● Companion objects can implements interfaces. interface Factory<T> { fun create(): T } class MyClass { companion object : Factory<MyClass> { @JvmStatic //converts to real static method override fun create(): MyClass = MyClass() } }
  • 47. Visibility Modifiers private - means visible inside this class only (including all its members); protected — same as private + visible in subclasses too; Override protected method are still protected. internal — any client inside this module who sees the declaring class sees its internal members. A module is a set of Kotlin files compiled together; public — any client who sees the declaring class sees its public members. (Default)
  • 48. Exception Kotlin does not have checked exceptions throw is an expression val s = person.name ?: throw IllegalArgumentException("Name required")
  • 49. Property: Get & Set class Strange(var value: Long) { var strangeValue: Long get() = value * 2 set(value){ if(value > 5) this.value = value } } fun main(args: Array<String>) { val customer = Strange(10) println(customer.strangeValue) //20 customer.strangeValue = 3 println(customer.strangeValue) //20 customer.strangeValue = 6 println(customer.strangeValue) //12 }
  • 50. Delegated properties: why me? class Delegate { operator fun getValue(thisRef: Any?, property: KProperty<*>): String { return "$thisRef, thank you for delegating '${property.name}' to me!" } operator fun setValue(thisRef: Any?, property: KProperty<*>, value: String) { println("$value has been assigned to '${property.name} in $thisRef.'") } } class Example { var p: String by Delegate() }
  • 51. Delegated properties: the lazy & the observable val lazyValue: String by lazy { println("computed!") "Hello" } fun main(args: Array<String>) { println(lazyValue) println(lazyValue) } class User { var n: String by Delegates.observable("empty") { prop, old, new -> println("$old -> $new") } } fun main(args: Array<String>) { val user = User() user.n = "first" user.n = "second" }
  • 52. Coroutine Coroutine ⋍ light-weight thread ● They are like threads, they run in parallel, wait for each other and they communicate. ● They are cheap, we can create many of those without having performance issues. ● They are executed in a thread pool. ● A thread can handle more than one coroutine. ● Thread became free until a coroutine is in waiting state. When the coroutine will return active, it doesn’t get the old thread, but it will use a free thread in the pool. https://github.com/Kotlin/kotlinx.coroutines/blob/master/coroutines-guide.md https://proandroiddev.com/approaching-kotlin-coroutines-an-extensive-feature-concurrent-programming-in-kotlin-eaaa19b003d2
  • 53. Coroutine is humble fun main(args: Array<String>) = runBlocking { val jobs = List(100_000) { launch { delay(1000L) print(".") } } jobs.forEach { it.join() } } fun main(args: Array<String>) { val jobs = List(100_000) { thread(start = true) { Thread.sleep(1000L) print(".") } } jobs.forEach { it.join() } } OUT OF MEMORY!!!
  • 54. Coroutine: suspend, async / await fun main(args: Array<String>) = runBlocking<Unit> { val time = measureTimeMillis { val one = doSomethingUsefulOne() val two = doSomethingUsefulTwo() println("The answer is ${one + two}") } println("Completed in $time ms") } suspend fun doSomethingUsefulOne(): Int { delay(1000L) return 13 } suspend fun doSomethingUsefulTwo(): Int { delay(1000L) return 29 } fun main(args: Array<String>) = runBlocking<Unit> { val time = measureTimeMillis { val one = async { doSomethingUsefulOne() } val two = async { doSomethingUsefulTwo() } println("The answer is ${one.await() + two.await()}") } println("Completed in $time ms") } suspend fun doSomethingUsefulOne(): Int { delay(1000L) return 13 } suspend fun doSomethingUsefulTwo(): Int { delay(1000L) return 29 } ~2 sec. ~1 sec.
  • 55. Coroutine is the basement Coroutine Actors Communication Sequence Process ?
  • 56. Now is the time to remember that Kotlin is good because the trade-off between synthesis and readable code is really good.
  • 58. Webapp: Gradle buildscript { ... dependencies { ... classpath "org.jetbrains.kotlin:kotlin-noarg:$kotlinVersion" } } ... apply plugin: "kotlin-jpa" group = 'it.devday' version = '0.0.1-SNAPSHOT' ... } JPA need an empty constructor in some entities, and Kotlin objects don’t have. To solve this issue we can use this plugin that will create an empty constructor in any object, without any change to our codebase.
  • 59. Webapp: Domain & Repository import it.devday.kotlincodemotion.domain.Contact import org.springframework.data....JpaRepository interface ItemRepository: JpaRepository<Item, Long> import javax.persistence.Entity import javax.persistence.GeneratedValue import javax.persistence.Id @Entity data class Item( @Id @GeneratedValue val id: Long, val description: String, val vat: Double, val price: Double, val quantity: Double)
  • 60. Webapp: Domain & Repository @Embeddable data class Price(val amount: Double) { operator fun plus(a: Price) = a.amount + this.amount operator fun rem(a: ValueAddedTax) = this.amount * (100 + a.percentage) / 100 } @Embeddable data class Quantity(val value: Double) @Embeddable data class ValueAddedTax(val percentage: Double) @Entity data class Item( @Id @GeneratedValue val id: Long, val description: String, @Embedded val vat: ValueAddedTax, @Embedded val price: Price, @Embedded val quantity: Quantity) { val grossPrice: Double get() = this.price % this.vat val total: Double get() = this.grossPrice * quantity.value }
  • 61. Webapp: Resource 1/2 @RestController @RequestMapping("/items") class ItemResource(val repository: ItemRepository) { @GetMapping //curl -XGET http://localhost:8080/items fun getAll() = repository.findAll() @GetMapping("/{id}") //curl -XGET http://localhost:8080/items/1 fun getAll(@PathVariable id: Long) = repository.findById(id)
  • 62. Webapp: Resource 2/2 @PostMapping //curl -XPOST http://localhost:8080/items -H 'Content-Type: application/json' -d '{"description":"Kotlin in action", "vat":{"percentage":10}, "price":{"amount":1.5}, "quantity":{"value":"10"}}' fun insert(@RequestBody item: Item) = repository.save(item) @DeleteMapping("/{id}") //curl -XDELETE http://localhost:8080/items/1 fun delete(@PathVariable id: Long) { val item = repository.findById(id).unwrap() item?.let { repository.delete(item) } } } wait...unwrap() doesn’t exist on Optional class
  • 63. Webapp: Application @SpringBootApplication class KotlinApplication fun <T> Optional<T>.unwrap(): T? = orElse(null) fun main(args: Array<String>) { runApplication<KotlinApplication>(*args) } unwrap()! array is passed element by element, it is used with vararg arguments public inline fun <reified T : kotlin.Any> runApplication(vararg args: kotlin.String) The generic type will be available in the method. Wow!
  • 64. Webapp: Where is my Repository? @RestController @RequestMapping("/items") class ItemResource() { @GetMapping //curl -XGET http://localhost:8080/items fun getAll() = Item.findAll() @GetMapping("/{id}") //curl -XGET http://localhost:8080/items/1 fun getAll(@PathVariable id: Long) = Item.findById(id) …...
  • 65. Webapp: Domain & Repository Dao @Entity data class Item(….) { …. companion object : Dao<Item, Long> } Why this approach? http://mavi.logdown.com/posts/5771422
  • 66. interface Dao<T, K> inline fun <reified T : Any, K> Dao<T, K>.findById(id: K): T = Db.exec { em -> em.find(T::class.java, id) } as T inline fun <reified T : Any, K> Dao<T, K>.save(item: T): Unit = Db.exec { em -> tx(em) { em.persist(item) } } as Unit ... …. fun tx(em: EntityManager, c: () -> Any): Any { try { em.transaction.begin() val result = c() em.transaction.commit() return result } finally { em.close() } } Webapp: Domain & Repository Dao
  • 67. @Component object Db : ApplicationContextAware { var ac: ApplicationContext? = null override fun setApplicationContext(applicationContext: ApplicationContext) { ac = applicationContext!! } fun exec(callback: (em: EntityManager) -> Any): Any { return callback(ac!!.getBean(EntityManagerFactory::class.java).createEntityManager()) } } Webapp: Domain & Repository Dao
  • 71. Useful resources https://kotlinlang.org/docs/reference/ https://spring.io/blog/2017/01/04/introducing-kotlin-support-in-spring-framework-5-0 https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/ https://dev.to/lovis/gang-of-four-patterns-in-kotlin https://github.com/volodymyrprokopyuk/kotlin-sdp https://github.com/gradle/gradle-script-kotlin https://speakerdeck.com/sdeleuze/functional-web-applications-with-spring-and-kotlin https://kotlinlang.org/docs/tutorials/httpservlets.html http://thetechnocafe.com/more-about-functions-in-kotlin/ https://nklmish.wordpress.com/2017/10/22/deprecated-in-kotlin/ https://kotlinlang.org/docs/tutorials/command-line.html https://agilewombat.com/2016/02/01/scala-vs-kotlin/ https://superkotlin.com/kotlin-vs-scala/ https://kotlinlang.org/docs/reference/type-safe-builders.html