SlideShare a Scribd company logo
1 of 43
Download to read offline
Kotlin Pro-Tips
Jorge Juan Barroso Carmona
Developer and GDE
jorge@karumi.com
@flipper83
Sergio GutierrezPedro Gomez
Davide Mendolia
Fran Toro
Antonio Lopez
Testing for android & iOS.
Trainings
Architecture, Patterns and
principles for Android & iOS.
Mastering Git.
Advanced mobile development.
Testing for android & iOS.
Architecture, Patterns and
principles for Android & iOS.
Companies For Everybody
Next open:
Testing Training 23 Jun.
Kotlin Training 20 Feb.
Swift Training 26 Mar.
Arch Training 3 Apr.
Adam Tornhill
“Computer languages differ not so much
in what they make possible, but in what
they make easy.”
Larry Wall
https://github.com/Karumi/SuperHeroesKotlin
https://github.com/Karumi/play-framework-kotlin
Increase Readability
improve command
pattern
@Inject
public class Application extends Controller, ParseableJson
{
public Application(
private final CreateKarumiDeveloper createKarumiDeveloper,
private final GetDeveloper getDeveloper
){/**/}
public CompletionStage<Result>
getDeveloper(String developerId){
getDeveloper.execute(UUID.fromString(developerId));
/**/
}
}
Adam Tornhill
Command
Pattern
JAVA
class Application @Inject constructor(
private val createKarumiDeveloper:CreateKarumiDeveloper,
private val getDeveloper: GetDeveloper
) : Controller(), ParseableJson {
fun getDeveloper(developerId: String):
CompletionStage<Result> = async {
getDeveloper(UUID.fromString(developerId)).fold(
ifLeft = this::processError,
ifRight = this::ok
)
}
}
Adam Tornhill
is this a method?
or is an object?
KOTLIN
class GetDeveloper @Inject constructor(
private val developerDao: DeveloperDao
) {
operator fun invoke(developerId: UUID):
Either<DeveloperError, Developer> =
developerDao[developerId].fold(
ifFailure = { DeveloperError.StorageError.left() },
ifSuccess = { it.toEither{ DeveloperError.NotFound }}
)
}
Adam Tornhill
Override
operators
getSuperHeroes()
KOTLIN
improve Data access
class GetDeveloper @Inject constructor(
private val developerDao: DeveloperDao
) {
operator fun invoke(developerId: UUID):
Either<DeveloperError, Developer> =
developerDao[developerId].fold(
ifFailure = { DeveloperError.StorageError.left() },
ifSuccess = { it.toEither{ DeveloperError.NotFound }}
)
}
Adam Tornhill
KOTLIN
is this a List?
operator fun get(id: UUID): Try<Option<Developer>> = Try {
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()
?.toDomain()
.toOption()
}
Adam Tornhill
KOTLIN
[id]
Handling
Exceptions
public class DeveloperDao {
public Developer getById(UUID id) throws Exception {
DeveloperEntity developerEntity =
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()
return developerMapper(developerEntity);
}
}
Adam Tornhill
JAVA
public class DeveloperDao {
public Developer getById(UUID id) throws Exception {
DeveloperEntity developerEntity =
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()
return developerMapper(developerEntity);
}
}
Adam Tornhill
JAVA
public class GetDeveloper {
/**/
public Developer execute(UUID developerId) {
try {
Developer developer =
developerDao.getById(devloperId);
return developer;
} catch (Exception e) {
return null;
}
}
}
Adam Tornhill
JAVA
public class GetDeveloper {
/**/
public Developer execute(UUID developerId) {
try {
Developer developer =
developerDao.getById(devloperId);
return developer;
} catch (Exception e) {
return null;
}
}
}
Adam Tornhill
JAVA
class DeveloperDao {
operator fun get(id: UUID): Try<Option<Developer>> =
Try {
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()?
.toDomain()
.toOption()
}
}
Adam Tornhill
Kotlin
class DeveloperDao {
operator fun get(id: UUID): Try<Option<Developer>> =
Try {
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()?
.toDomain()
.toOption()
}
}
Adam Tornhill
Kotlin
class DeveloperDao {
operator fun get(id: UUID): Try<Option<Developer>> =
Try {
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()?
.toDomain()
.toOption()
}
}
Adam Tornhill
Kotlin
class DeveloperDao {
operator fun get(id: UUID): Try<Option<Developer>> =
Try {
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()?
.toDomain()
.toOption()
}
}
Adam Tornhill
Kotlin
class DeveloperDao {
operator fun get(id: UUID): Try<Option<Developer>> =
Try {
DeveloperEntity.DAO
.query()
.where()
.idEq(id)
.findOne()?
.toDomain()
.toOption()
}
}
Adam Tornhill
Kotlin
operator fun invoke(developerId: UUID):
Either<DeveloperError, Developer> =
developerDao[developerId]
.toEither{ DeveloperError.NotFound }
.mapLeft { StorageError }
Adam Tornhill
Kotlin
operator fun invoke(developerId: UUID):
Either<DeveloperError, Developer> =
developerDao[developerId]
.toEither{ DeveloperError.NotFound }
.mapLeft { StorageError }
Adam Tornhill
Kotlin
Try<Option<Developer>>
operator fun invoke(developerId: UUID):
Either<DeveloperError, Developer> =
developerDao[developerId]
.toEither{ DeveloperError.NotFound }
.mapLeft { StorageError }
Adam Tornhill
Kotlin
fun getDeveloper(developerId: String):
CompletionStage<Result> = async {
getDeveloper(UUID.fromString(developerId))
.fold(
ifLeft = this::processError,
ifRight = this::ok
)
}
Adam Tornhill
Kotlin
fun getDeveloper(developerId: String):
CompletionStage<Result> = async {
getDeveloper(UUID.fromString(developerId))
.fold(
ifLeft = this::processError,
ifRight = this::ok
)
}
Adam Tornhill
Kotlin
Compiler check
sealed classes
private fun processError(
developerError: DeveloperError
): Result =
when (developerError) {
DeveloperError.StorageError ->internalServerError()
DeveloperError.NotFound -> notFound()
DeveloperError.NotKarumier ->
badRequest("Onlykarumies")
}
Adam Tornhill
Kotlin
private fun processError(
developerError: DeveloperError
): Result =
when (developerError) {
DeveloperError.StorageError ->internalServerError()
DeveloperError.NotFound -> notFound()
DeveloperError.NotKarumier ->
badRequest("Onlykarumies")
}
Adam Tornhill
Kotlin
private fun processError(
developerError: DeveloperError
): Result =
when (developerError) {
DeveloperError.StorageError ->internalServerError()
DeveloperError.NotFound -> notFound()
DeveloperError.NotKarumier ->
badRequest("Onlykarumies")
}
Adam Tornhill
Kotlin
Compile
Error
sealed class DeveloperError {
object StorageError : DeveloperError()
object NotFound : DeveloperError()
object NotKarumier : DeveloperError()
}
Adam Tornhill
Kotlin
exhaustive
private fun onStatusChanged(status: Status) {
when (status) {
is Status.Idle -> {
loadingView.visibility = GONE
hideItems()
}
is Status.Fetching ->
loadingView.visibility = VISIBLE
is Status.Fetched -> {
loadingView.visibility = GONE
showItems()
}
}.exhaustive
}
Adam Tornhill
Kotlin
private fun onStatusChanged(status: Status) {
when (status) {
is Status.Idle -> {
loadingView.visibility = GONE
hideItems()
}
is Status.Fetching ->
loadingView.visibility = VISIBLE
is Status.Fetched -> {
loadingView.visibility = GONE
showItems()
}
}.exhaustive
}
Adam Tornhill
Kotlin
val Any?.exhaustive get() = Unit
Definición de modelos
data class Developer(
val id: UUID = UUID.randomUUID(),
val username: String,
val email: String?
)
Adam Tornhill
Kotlin
val developer = Developer(
val email = “jorge@karumi.com",
val username = “Jorge Carmona”
)
val developer = Developer(
val username = “Jorge Carmona”
)
Bibliography
They’re the cracks!
Clean Code. Uncle Bob. 2008
Kotlin For Android Developers. Antonio Leiva. 2015
GitHub AsyncAwait . metalabdesign.
Github funKTionale. MarioAriasC.
Kodein. Salomon Brys.
Karumi Blog and Katas on github.
Find meI am very social!
jorge@karumi.com
@flipper83
Questions?
Jorge Carmona | Kotlin pro-tips | Codemotion Madrid 2018

More Related Content

Similar to Jorge Carmona | Kotlin pro-tips | Codemotion Madrid 2018

Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguajeKotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguajeVíctor Leonel Orozco López
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Omar Miatello
 
Kotlin a problem solver - gdd extended pune
Kotlin   a problem solver - gdd extended puneKotlin   a problem solver - gdd extended pune
Kotlin a problem solver - gdd extended puneHardik Trivedi
 
Android design patterns
Android design patternsAndroid design patterns
Android design patternsVitali Pekelis
 
Excuse me, sir, do you have a moment to talk about tests in Kotlin
Excuse me, sir, do you have a moment to talk about tests in KotlinExcuse me, sir, do you have a moment to talk about tests in Kotlin
Excuse me, sir, do you have a moment to talk about tests in Kotlinleonsabr
 
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaKotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaVíctor Leonel Orozco López
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampKai Koenig
 
Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJiayun Zhou
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - GreachHamletDRC
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKGuardSquare
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon Berlin
 

Similar to Jorge Carmona | Kotlin pro-tips | Codemotion Madrid 2018 (20)

Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguajeKotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
Kotlin+MicroProfile: Enseñando trucos de 20 años a un nuevo lenguaje
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
 
Kotlin a problem solver - gdd extended pune
Kotlin   a problem solver - gdd extended puneKotlin   a problem solver - gdd extended pune
Kotlin a problem solver - gdd extended pune
 
Android design patterns
Android design patternsAndroid design patterns
Android design patterns
 
Excuse me, sir, do you have a moment to talk about tests in Kotlin
Excuse me, sir, do you have a moment to talk about tests in KotlinExcuse me, sir, do you have a moment to talk about tests in Kotlin
Excuse me, sir, do you have a moment to talk about tests in Kotlin
 
Clean code
Clean codeClean code
Clean code
 
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem novaKotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
Kotlin+MicroProfile: Ensinando 20 anos para uma linguagem nova
 
從零開始學 Android
從零開始學 Android從零開始學 Android
從零開始學 Android
 
Annotation processing tool
Annotation processing toolAnnotation processing tool
Annotation processing tool
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Summer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcampSummer of Tech 2017 - Kotlin/Android bootcamp
Summer of Tech 2017 - Kotlin/Android bootcamp
 
Java EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSFJava EE 6 CDI Integrates with Spring & JSF
Java EE 6 CDI Integrates with Spring & JSF
 
New Ideas for Old Code - Greach
New Ideas for Old Code - GreachNew Ideas for Old Code - Greach
New Ideas for Old Code - Greach
 
Clean code
Clean codeClean code
Clean code
 
Robotium Tutorial
Robotium TutorialRobotium Tutorial
Robotium Tutorial
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
 

More from Codemotion

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Codemotion
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyCodemotion
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaCodemotion
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserCodemotion
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Codemotion
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Codemotion
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Codemotion
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 - Codemotion
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Codemotion
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Codemotion
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Codemotion
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Codemotion
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Codemotion
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Codemotion
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Codemotion
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...Codemotion
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Codemotion
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Codemotion
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Codemotion
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Codemotion
 

More from Codemotion (20)

Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
Fuzz-testing: A hacker's approach to making your code more secure | Pascal Ze...
 
Pompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending storyPompili - From hero to_zero: The FatalNoise neverending story
Pompili - From hero to_zero: The FatalNoise neverending story
 
Pastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storiaPastore - Commodore 65 - La storia
Pastore - Commodore 65 - La storia
 
Pennisi - Essere Richard Altwasser
Pennisi - Essere Richard AltwasserPennisi - Essere Richard Altwasser
Pennisi - Essere Richard Altwasser
 
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
Michel Schudel - Let's build a blockchain... in 40 minutes! - Codemotion Amst...
 
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
Richard Süselbeck - Building your own ride share app - Codemotion Amsterdam 2019
 
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
Eward Driehuis - What we learned from 20.000 attacks - Codemotion Amsterdam 2019
 
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 - Francesco Baldassarri  - Deliver Data at Scale - Codemotion Amsterdam 2019 -
Francesco Baldassarri - Deliver Data at Scale - Codemotion Amsterdam 2019 -
 
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
Martin Förtsch, Thomas Endres - Stereoscopic Style Transfer AI - Codemotion A...
 
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
Melanie Rieback, Klaus Kursawe - Blockchain Security: Melting the "Silver Bul...
 
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
Angelo van der Sijpt - How well do you know your network stack? - Codemotion ...
 
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
Lars Wolff - Performance Testing for DevOps in the Cloud - Codemotion Amsterd...
 
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
Sascha Wolter - Conversational AI Demystified - Codemotion Amsterdam 2019
 
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
Michele Tonutti - Scaling is caring - Codemotion Amsterdam 2019
 
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
Pat Hermens - From 100 to 1,000+ deployments a day - Codemotion Amsterdam 2019
 
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
James Birnie - Using Many Worlds of Compute Power with Quantum - Codemotion A...
 
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
Don Goodman-Wilson - Chinese food, motor scooters, and open source developmen...
 
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
Pieter Omvlee - The story behind Sketch - Codemotion Amsterdam 2019
 
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
Dave Farley - Taking Back “Software Engineering” - Codemotion Amsterdam 2019
 
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
Joshua Hoffman - Should the CTO be Coding? - Codemotion Amsterdam 2019
 

Recently uploaded

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

Jorge Carmona | Kotlin pro-tips | Codemotion Madrid 2018

  • 1. Kotlin Pro-Tips Jorge Juan Barroso Carmona Developer and GDE jorge@karumi.com @flipper83
  • 2. Sergio GutierrezPedro Gomez Davide Mendolia Fran Toro Antonio Lopez
  • 3. Testing for android & iOS. Trainings Architecture, Patterns and principles for Android & iOS. Mastering Git. Advanced mobile development. Testing for android & iOS. Architecture, Patterns and principles for Android & iOS. Companies For Everybody Next open: Testing Training 23 Jun. Kotlin Training 20 Feb. Swift Training 26 Mar. Arch Training 3 Apr.
  • 4.
  • 5. Adam Tornhill “Computer languages differ not so much in what they make possible, but in what they make easy.” Larry Wall
  • 9. @Inject public class Application extends Controller, ParseableJson { public Application( private final CreateKarumiDeveloper createKarumiDeveloper, private final GetDeveloper getDeveloper ){/**/} public CompletionStage<Result> getDeveloper(String developerId){ getDeveloper.execute(UUID.fromString(developerId)); /**/ } } Adam Tornhill Command Pattern JAVA
  • 10. class Application @Inject constructor( private val createKarumiDeveloper:CreateKarumiDeveloper, private val getDeveloper: GetDeveloper ) : Controller(), ParseableJson { fun getDeveloper(developerId: String): CompletionStage<Result> = async { getDeveloper(UUID.fromString(developerId)).fold( ifLeft = this::processError, ifRight = this::ok ) } } Adam Tornhill is this a method? or is an object? KOTLIN
  • 11. class GetDeveloper @Inject constructor( private val developerDao: DeveloperDao ) { operator fun invoke(developerId: UUID): Either<DeveloperError, Developer> = developerDao[developerId].fold( ifFailure = { DeveloperError.StorageError.left() }, ifSuccess = { it.toEither{ DeveloperError.NotFound }} ) } Adam Tornhill Override operators getSuperHeroes() KOTLIN
  • 13. class GetDeveloper @Inject constructor( private val developerDao: DeveloperDao ) { operator fun invoke(developerId: UUID): Either<DeveloperError, Developer> = developerDao[developerId].fold( ifFailure = { DeveloperError.StorageError.left() }, ifSuccess = { it.toEither{ DeveloperError.NotFound }} ) } Adam Tornhill KOTLIN is this a List?
  • 14. operator fun get(id: UUID): Try<Option<Developer>> = Try { DeveloperEntity.DAO .query() .where() .idEq(id) .findOne() ?.toDomain() .toOption() } Adam Tornhill KOTLIN [id]
  • 16. public class DeveloperDao { public Developer getById(UUID id) throws Exception { DeveloperEntity developerEntity = DeveloperEntity.DAO .query() .where() .idEq(id) .findOne() return developerMapper(developerEntity); } } Adam Tornhill JAVA
  • 17. public class DeveloperDao { public Developer getById(UUID id) throws Exception { DeveloperEntity developerEntity = DeveloperEntity.DAO .query() .where() .idEq(id) .findOne() return developerMapper(developerEntity); } } Adam Tornhill JAVA
  • 18. public class GetDeveloper { /**/ public Developer execute(UUID developerId) { try { Developer developer = developerDao.getById(devloperId); return developer; } catch (Exception e) { return null; } } } Adam Tornhill JAVA
  • 19. public class GetDeveloper { /**/ public Developer execute(UUID developerId) { try { Developer developer = developerDao.getById(devloperId); return developer; } catch (Exception e) { return null; } } } Adam Tornhill JAVA
  • 20. class DeveloperDao { operator fun get(id: UUID): Try<Option<Developer>> = Try { DeveloperEntity.DAO .query() .where() .idEq(id) .findOne()? .toDomain() .toOption() } } Adam Tornhill Kotlin
  • 21. class DeveloperDao { operator fun get(id: UUID): Try<Option<Developer>> = Try { DeveloperEntity.DAO .query() .where() .idEq(id) .findOne()? .toDomain() .toOption() } } Adam Tornhill Kotlin
  • 22. class DeveloperDao { operator fun get(id: UUID): Try<Option<Developer>> = Try { DeveloperEntity.DAO .query() .where() .idEq(id) .findOne()? .toDomain() .toOption() } } Adam Tornhill Kotlin
  • 23. class DeveloperDao { operator fun get(id: UUID): Try<Option<Developer>> = Try { DeveloperEntity.DAO .query() .where() .idEq(id) .findOne()? .toDomain() .toOption() } } Adam Tornhill Kotlin
  • 24. class DeveloperDao { operator fun get(id: UUID): Try<Option<Developer>> = Try { DeveloperEntity.DAO .query() .where() .idEq(id) .findOne()? .toDomain() .toOption() } } Adam Tornhill Kotlin
  • 25. operator fun invoke(developerId: UUID): Either<DeveloperError, Developer> = developerDao[developerId] .toEither{ DeveloperError.NotFound } .mapLeft { StorageError } Adam Tornhill Kotlin
  • 26. operator fun invoke(developerId: UUID): Either<DeveloperError, Developer> = developerDao[developerId] .toEither{ DeveloperError.NotFound } .mapLeft { StorageError } Adam Tornhill Kotlin Try<Option<Developer>>
  • 27. operator fun invoke(developerId: UUID): Either<DeveloperError, Developer> = developerDao[developerId] .toEither{ DeveloperError.NotFound } .mapLeft { StorageError } Adam Tornhill Kotlin
  • 28. fun getDeveloper(developerId: String): CompletionStage<Result> = async { getDeveloper(UUID.fromString(developerId)) .fold( ifLeft = this::processError, ifRight = this::ok ) } Adam Tornhill Kotlin
  • 29. fun getDeveloper(developerId: String): CompletionStage<Result> = async { getDeveloper(UUID.fromString(developerId)) .fold( ifLeft = this::processError, ifRight = this::ok ) } Adam Tornhill Kotlin
  • 32. private fun processError( developerError: DeveloperError ): Result = when (developerError) { DeveloperError.StorageError ->internalServerError() DeveloperError.NotFound -> notFound() DeveloperError.NotKarumier -> badRequest("Onlykarumies") } Adam Tornhill Kotlin
  • 33. private fun processError( developerError: DeveloperError ): Result = when (developerError) { DeveloperError.StorageError ->internalServerError() DeveloperError.NotFound -> notFound() DeveloperError.NotKarumier -> badRequest("Onlykarumies") } Adam Tornhill Kotlin
  • 34. private fun processError( developerError: DeveloperError ): Result = when (developerError) { DeveloperError.StorageError ->internalServerError() DeveloperError.NotFound -> notFound() DeveloperError.NotKarumier -> badRequest("Onlykarumies") } Adam Tornhill Kotlin Compile Error
  • 35. sealed class DeveloperError { object StorageError : DeveloperError() object NotFound : DeveloperError() object NotKarumier : DeveloperError() } Adam Tornhill Kotlin
  • 37. private fun onStatusChanged(status: Status) { when (status) { is Status.Idle -> { loadingView.visibility = GONE hideItems() } is Status.Fetching -> loadingView.visibility = VISIBLE is Status.Fetched -> { loadingView.visibility = GONE showItems() } }.exhaustive } Adam Tornhill Kotlin
  • 38. private fun onStatusChanged(status: Status) { when (status) { is Status.Idle -> { loadingView.visibility = GONE hideItems() } is Status.Fetching -> loadingView.visibility = VISIBLE is Status.Fetched -> { loadingView.visibility = GONE showItems() } }.exhaustive } Adam Tornhill Kotlin val Any?.exhaustive get() = Unit
  • 40. data class Developer( val id: UUID = UUID.randomUUID(), val username: String, val email: String? ) Adam Tornhill Kotlin val developer = Developer( val email = “jorge@karumi.com", val username = “Jorge Carmona” ) val developer = Developer( val username = “Jorge Carmona” )
  • 41. Bibliography They’re the cracks! Clean Code. Uncle Bob. 2008 Kotlin For Android Developers. Antonio Leiva. 2015 GitHub AsyncAwait . metalabdesign. Github funKTionale. MarioAriasC. Kodein. Salomon Brys. Karumi Blog and Katas on github.
  • 42. Find meI am very social! jorge@karumi.com @flipper83 Questions?