SlideShare a Scribd company logo
1 of 30
training@instil.co
January 2019
© Instil Software 2018
Kotlin for All the Things
Kotlin Native
@BoyleEamonn
Eamonn Boyle
Me
Us
My Dog
Google Maps
2010: Work begins on Kotlin within JetBrains
2011: First public announcement on Kotlin
2012: Open sourced under Apache 2 license
2016: Version one released
2017: First class support on Android
2018: Version 1.3 released
A Kotlin Timeline
We’ve bought into Kotlin in a big way
Kotlin…Ok…we’re obsessed
We held a workshop at the conference
• React Web App with Kotlin on Server & Browser
Kotlin…Ok…we’re obsessed
If you’re working on the Java Virtual Machine, try not to use Java
Having done C# for many years I was so happy to see Kotlin for the JVM
Problems with Java
• Verbose, Verbose, Verbose, Verbose, Verbose, Verbose, Verbose, Verbose,
• Nulls
• Completely OO
Why Koltin - Java – Yuck!
No need to wait - the interop story is so good
• Call into all that legacy Java code easily
• Make calls into your new Kotlin code from Java easily
Really concise, yet clear syntax
• Less is more
• “Borrows” the best bits of other languages
• Less baggage
Why Kotlin – So Much to Like
Null Safety
String Templates
Default parameters
Extensions
Free Functions
Coroutines
Single Expression Functions
Reified generics
Data classes and Properties
Type Inference
Smart Casts
Operator overloading
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
}
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
}
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
Basic Model Classes – Java
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
}
Basic Model Classes – Java vs Kotlin
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
}
data class Movie(var title: String,
var description: String,
var rating: Rating,
var genre: Genre) {
}
Java Kotlin
Basic Model Classes – Java vs Kotlin
import java.util.Objects;
public class Movie {
private String title;
private String description;
private Rating rating;
private Genre genre;
public Movie(String title, String description, Rating rating, Genre genre) {
this.title = title;
this.description = description;
this.rating = rating;
this.genre = genre;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Rating getRating() {
return rating;
}
public void setRating(Rating rating) {
this.rating = rating;
}
public Genre getGenre() {
return genre;
}
public void setGenre(Genre genre) {
this.genre = genre;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Movie movie = (Movie) o;
return Objects.equals(title, movie.title) &&
Objects.equals(description, movie.description) &&
Objects.equals(rating, movie.rating) &&
Objects.equals(genre, movie.genre);
}
@Override
public int hashCode() {
return Objects.hash(title, description, rating, genre);
}
@Override
public String toString() {
return "Movie{" +
"title='" + title + ''' +
", description='" + description + ''' +
", rating=" + rating +
", genre=" + genre +
'}';
}
}
data class Movie(var title: String,
var description: String,
var rating: Rating,
var genre: Genre) {
}
We also get hashCode(), equals(), toString() and more…
External libraries and tools like Lombok will help with Java
Java Kotlin
Null Safety
private fun processUserPolicy(user: User) {
val policy = user.policy
if (policy.isComplete) {
policyProcessor.process(policy)
}
}
private static void processUserPolicy(User user) {
if (user != null && user.getPolicy() != null) {
Policy policy = user.getPolicy();
if (policy.isComplete()) {
policyProcessor.process(policy);
}
}
}
Java
Kotlin
Functional Chaining – vs Java
Reified Generics with a single primitive representation makes the code simpler
double averageSalary = employees
.stream()
.filter(x ->
x.getDepartment() == Engineering)
.mapToInt(Employee::getSalary)
.average()
.orElse(0);
Java
val averageSalary = employees
.filter { it.department === Engineering }
.map { it.salary }
.average()
Kotlin
Kotlin was originally for writing server and desktop Java
• That’s what JetBrains were building themselves
This evolved further into supporting Android
• Which is now what it’s very popular for
JetBrains went further to support the Browser in Kotlin/JS and native in
Kotlin.Native
Kotlin Platforms
Kotlin/Native is a technology for compiling Kotlin code to native binaries
• It runs without a virtual machine
• The output is NOT portable
Although the binary output is not portable, the source IS portable
• The compiler can compile the same source to multiple outputs/platforms
• The source can be placed into a multiplatform project and used for JVM,
JS etc
Kotlin Native
Kotlin Compiler LLVMSource Native Binary
LLVM IR
Supported platforms include,
• iOS (arm32, arm64, emulator x86_64)
• MacOS (x86_64)
• Android (arm32, arm64)
• Windows (mingw x86_64)
• Linux (x86_64, arm32, MIPS, MIPS little endian)
• WebAssembly (wasm32)
We can link to or dynamically call into other native libraries
• C headers or Apple Frameworks
Note – Kotlin/Native is still beta
Kotlin Native
© Instil Software 2018
• Image Convolution
https://en.wikipedia.org/wiki/Kernel_(image_processing)
https://rosettacode.org/wiki/Image_convolution#Kotlin
Demo
Multiplatform project – common and platform specific code
• Using ‘expect’ and ‘actual’
API compatibility shown on doc pages
Demonstration Points – Multiplatform APIs
Common things such as Kotlin.io aren’t available
You can use Posix and interop to achieve functionality or use other multiplatform
libraries
To simplify working with native code we have some methods
• refTo
• pin
• unpin
Demonstration Points – Multiplatform APIs
import kotlinx.cinterop.*
import platform.posix.*
import kotlinx.io.*
Now supports Gradle for building so you can use IntelliJ
For more advanced native debugging you’ll need native debugger e.g. Clion
Demonstration Points - Build
© Instil Software 2018
Summary
Kotlin is spreading
• The right balance between simplicity and productivity
• Easy interoperation with Java
Kotlin/Native is very interesting
• Still beta but JetBrains are working hard
• Provides a solution for iOS support
A good set of libraries allows you to be productive
• Kotlin/Native doesn’t have that…yet
• The interop and wrapping of other libraries will be key
• First class support of more Kotlin libraries will be key
Kotlin, soon to be the right once, run anywhere language
Summary
Well….maybe
Questions?

More Related Content

Similar to Kotlin for All Platforms

Kotlin for Android - Goto Copenhagan 2019
Kotlin for Android - Goto Copenhagan 2019Kotlin for Android - Goto Copenhagan 2019
Kotlin for Android - Goto Copenhagan 2019Eamonn Boyle
 
Transitioning Android Teams Into Kotlin
Transitioning Android Teams Into KotlinTransitioning Android Teams Into Kotlin
Transitioning Android Teams Into KotlinGarth Gilmour
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaDILo Surabaya
 
Be More Productive with Kotlin
Be More Productive with KotlinBe More Productive with Kotlin
Be More Productive with KotlinBrandon Wever
 
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
 
Programming with Kotlin
Programming with KotlinProgramming with Kotlin
Programming with KotlinDavid Gassner
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devsAdit Lal
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Tudor Dragan
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Omar Miatello
 
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveWriting Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveAndré Oriani
 
Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)
Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)
Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)Ahmed Nabil
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developersMohamed Wael
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developementfrwebhelp
 
Dear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooDear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooVivek Chanddru
 

Similar to Kotlin for All Platforms (20)

Kotlin for Android - Goto Copenhagan 2019
Kotlin for Android - Goto Copenhagan 2019Kotlin for Android - Goto Copenhagan 2019
Kotlin for Android - Goto Copenhagan 2019
 
Transitioning Android Teams Into Kotlin
Transitioning Android Teams Into KotlinTransitioning Android Teams Into Kotlin
Transitioning Android Teams Into Kotlin
 
Having Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo SurabayaHaving Fun with Kotlin Android - DILo Surabaya
Having Fun with Kotlin Android - DILo Surabaya
 
From Java to Python
From Java to PythonFrom Java to Python
From Java to Python
 
Be More Productive with Kotlin
Be More Productive with KotlinBe More Productive with Kotlin
Be More Productive with 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
 
Kotlin After 9 Months
Kotlin After 9 MonthsKotlin After 9 Months
Kotlin After 9 Months
 
Programming with Kotlin
Programming with KotlinProgramming with Kotlin
Programming with Kotlin
 
Kotlin for Android devs
Kotlin for Android devsKotlin for Android devs
Kotlin for Android devs
 
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
 
Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01Android & Kotlin - The code awakens #01
Android & Kotlin - The code awakens #01
 
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna loveWriting Kotlin Multiplatform libraries that your iOS teammates are gonna love
Writing Kotlin Multiplatform libraries that your iOS teammates are gonna love
 
Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)
Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)
Kotlin mufix 31 10-2019 by Ahmed Nabil(AhmedNMahran)
 
Introduction to Kotlin for Android developers
Introduction to Kotlin for Android developersIntroduction to Kotlin for Android developers
Introduction to Kotlin for Android developers
 
Koin Quickstart
Koin QuickstartKoin Quickstart
Koin Quickstart
 
CSharp presentation and software developement
CSharp presentation and software developementCSharp presentation and software developement
CSharp presentation and software developement
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 
Dear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans tooDear Kotliners - Java Developers are Humans too
Dear Kotliners - Java Developers are Humans too
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 

More from Eamonn Boyle

2019-06 - Goto Amsterdam - Microservices
2019-06 - Goto Amsterdam - Microservices2019-06 - Goto Amsterdam - Microservices
2019-06 - Goto Amsterdam - MicroservicesEamonn Boyle
 
2019-01-29 - Demystifying Kotlin Coroutines
2019-01-29 - Demystifying Kotlin Coroutines2019-01-29 - Demystifying Kotlin Coroutines
2019-01-29 - Demystifying Kotlin CoroutinesEamonn Boyle
 
BelTech 2017 - Building Quality in the Browser
BelTech 2017 - Building Quality in the BrowserBelTech 2017 - Building Quality in the Browser
BelTech 2017 - Building Quality in the BrowserEamonn Boyle
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesEamonn Boyle
 
Being Expressive in Code
Being Expressive in CodeBeing Expressive in Code
Being Expressive in CodeEamonn Boyle
 
2018-09 - F# and Fable
2018-09 - F# and Fable2018-09 - F# and Fable
2018-09 - F# and FableEamonn Boyle
 

More from Eamonn Boyle (6)

2019-06 - Goto Amsterdam - Microservices
2019-06 - Goto Amsterdam - Microservices2019-06 - Goto Amsterdam - Microservices
2019-06 - Goto Amsterdam - Microservices
 
2019-01-29 - Demystifying Kotlin Coroutines
2019-01-29 - Demystifying Kotlin Coroutines2019-01-29 - Demystifying Kotlin Coroutines
2019-01-29 - Demystifying Kotlin Coroutines
 
BelTech 2017 - Building Quality in the Browser
BelTech 2017 - Building Quality in the BrowserBelTech 2017 - Building Quality in the Browser
BelTech 2017 - Building Quality in the Browser
 
ASP .Net Core SPA Templates
ASP .Net Core SPA TemplatesASP .Net Core SPA Templates
ASP .Net Core SPA Templates
 
Being Expressive in Code
Being Expressive in CodeBeing Expressive in Code
Being Expressive in Code
 
2018-09 - F# and Fable
2018-09 - F# and Fable2018-09 - F# and Fable
2018-09 - F# and Fable
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxnada99848
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
software engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptxsoftware engineering Chapter 5 System modeling.pptx
software engineering Chapter 5 System modeling.pptx
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 

Kotlin for All Platforms

  • 1. training@instil.co January 2019 © Instil Software 2018 Kotlin for All the Things Kotlin Native @BoyleEamonn Eamonn Boyle
  • 2. Me
  • 3. Us
  • 6.
  • 7. 2010: Work begins on Kotlin within JetBrains 2011: First public announcement on Kotlin 2012: Open sourced under Apache 2 license 2016: Version one released 2017: First class support on Android 2018: Version 1.3 released A Kotlin Timeline
  • 8. We’ve bought into Kotlin in a big way Kotlin…Ok…we’re obsessed
  • 9. We held a workshop at the conference • React Web App with Kotlin on Server & Browser Kotlin…Ok…we’re obsessed
  • 10. If you’re working on the Java Virtual Machine, try not to use Java Having done C# for many years I was so happy to see Kotlin for the JVM Problems with Java • Verbose, Verbose, Verbose, Verbose, Verbose, Verbose, Verbose, Verbose, • Nulls • Completely OO Why Koltin - Java – Yuck!
  • 11. No need to wait - the interop story is so good • Call into all that legacy Java code easily • Make calls into your new Kotlin code from Java easily Really concise, yet clear syntax • Less is more • “Borrows” the best bits of other languages • Less baggage Why Kotlin – So Much to Like Null Safety String Templates Default parameters Extensions Free Functions Coroutines Single Expression Functions Reified generics Data classes and Properties Type Inference Smart Casts Operator overloading
  • 12. Basic Model Classes – Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; }
  • 13. Basic Model Classes – Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } }
  • 14. Basic Model Classes – Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; }
  • 15. Basic Model Classes – Java public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } }
  • 16. Basic Model Classes – Java vs Kotlin public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } } data class Movie(var title: String, var description: String, var rating: Rating, var genre: Genre) { } Java Kotlin
  • 17. Basic Model Classes – Java vs Kotlin import java.util.Objects; public class Movie { private String title; private String description; private Rating rating; private Genre genre; public Movie(String title, String description, Rating rating, Genre genre) { this.title = title; this.description = description; this.rating = rating; this.genre = genre; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Rating getRating() { return rating; } public void setRating(Rating rating) { this.rating = rating; } public Genre getGenre() { return genre; } public void setGenre(Genre genre) { this.genre = genre; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Movie movie = (Movie) o; return Objects.equals(title, movie.title) && Objects.equals(description, movie.description) && Objects.equals(rating, movie.rating) && Objects.equals(genre, movie.genre); } @Override public int hashCode() { return Objects.hash(title, description, rating, genre); } @Override public String toString() { return "Movie{" + "title='" + title + ''' + ", description='" + description + ''' + ", rating=" + rating + ", genre=" + genre + '}'; } } data class Movie(var title: String, var description: String, var rating: Rating, var genre: Genre) { } We also get hashCode(), equals(), toString() and more… External libraries and tools like Lombok will help with Java Java Kotlin
  • 18.
  • 19. Null Safety private fun processUserPolicy(user: User) { val policy = user.policy if (policy.isComplete) { policyProcessor.process(policy) } } private static void processUserPolicy(User user) { if (user != null && user.getPolicy() != null) { Policy policy = user.getPolicy(); if (policy.isComplete()) { policyProcessor.process(policy); } } } Java Kotlin
  • 20. Functional Chaining – vs Java Reified Generics with a single primitive representation makes the code simpler double averageSalary = employees .stream() .filter(x -> x.getDepartment() == Engineering) .mapToInt(Employee::getSalary) .average() .orElse(0); Java val averageSalary = employees .filter { it.department === Engineering } .map { it.salary } .average() Kotlin
  • 21. Kotlin was originally for writing server and desktop Java • That’s what JetBrains were building themselves This evolved further into supporting Android • Which is now what it’s very popular for JetBrains went further to support the Browser in Kotlin/JS and native in Kotlin.Native Kotlin Platforms
  • 22. Kotlin/Native is a technology for compiling Kotlin code to native binaries • It runs without a virtual machine • The output is NOT portable Although the binary output is not portable, the source IS portable • The compiler can compile the same source to multiple outputs/platforms • The source can be placed into a multiplatform project and used for JVM, JS etc Kotlin Native Kotlin Compiler LLVMSource Native Binary LLVM IR
  • 23. Supported platforms include, • iOS (arm32, arm64, emulator x86_64) • MacOS (x86_64) • Android (arm32, arm64) • Windows (mingw x86_64) • Linux (x86_64, arm32, MIPS, MIPS little endian) • WebAssembly (wasm32) We can link to or dynamically call into other native libraries • C headers or Apple Frameworks Note – Kotlin/Native is still beta Kotlin Native
  • 24. © Instil Software 2018 • Image Convolution https://en.wikipedia.org/wiki/Kernel_(image_processing) https://rosettacode.org/wiki/Image_convolution#Kotlin Demo
  • 25. Multiplatform project – common and platform specific code • Using ‘expect’ and ‘actual’ API compatibility shown on doc pages Demonstration Points – Multiplatform APIs
  • 26. Common things such as Kotlin.io aren’t available You can use Posix and interop to achieve functionality or use other multiplatform libraries To simplify working with native code we have some methods • refTo • pin • unpin Demonstration Points – Multiplatform APIs import kotlinx.cinterop.* import platform.posix.* import kotlinx.io.*
  • 27. Now supports Gradle for building so you can use IntelliJ For more advanced native debugging you’ll need native debugger e.g. Clion Demonstration Points - Build
  • 28. © Instil Software 2018 Summary
  • 29. Kotlin is spreading • The right balance between simplicity and productivity • Easy interoperation with Java Kotlin/Native is very interesting • Still beta but JetBrains are working hard • Provides a solution for iOS support A good set of libraries allows you to be productive • Kotlin/Native doesn’t have that…yet • The interop and wrapping of other libraries will be key • First class support of more Kotlin libraries will be key Kotlin, soon to be the right once, run anywhere language Summary Well….maybe