SlideShare a Scribd company logo
1 of 50
Download to read offline
Don’t try Kotlin

on the Back-end or

You’ll Get Hooked!
by Oleksii Fedorov
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
Who am I?
Oleksii Fedorov
• Sr Software Engineer @ Pivotal Berlin
• Entrepreneur In-house @ Pivotal Berlin
• Founder @ iwillteachyoukotlin.com
• Kotlin on Back-end in Production for 2+ years
• Programming for more than 2/3 of my life
• Writer, mentor, coach
2
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
3
You don’t have to rewrite
anything
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
4
You don’t have to rewrite anything
1) Add tiny change to your Gradle/Maven build, e.g for Gradle:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
5
You don’t have to rewrite anything
2) Create your 1st Kotlin file, in same directory with Java files:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
6
You don’t have to rewrite anything
3) Use your Java (code and libs) from Kotlin, as if it was Kotlin:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
7
You don’t have to rewrite anything
4) Use your Kotlin (code and libs) from Java, as if it was Java:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
8
Barrier for entry is so low
(so it’s almost a crime to not give it a shot)
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
9
Great support on back-end
• Spring (Boot) is fully supported (any recent
version). And since Spring 5 (Boot 2) offers more
concise Kotlinesque APIs
• Vert.x provides dedicated Kotlin support
• Ktor, specifically created for Kotlin, offers high
scalability and easy-to-use idiomatic APIs
• And virtually almost any JVM library
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
10
Compile-time null-safety
Compile error now > Runtime exception 1 year later
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
11
Compile-time null-safety
Compiler forces you to handle possible null value:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
12
Compile-time null-safety
Instead of “if” statement, leverage safe calls:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
13
Compile-time null-safety
Handle edge cases with Elvis operator
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
14
Compile-time null-safety
Thank you to Kotlin team for Smart-casting:
as opposed to:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
15
Compile-time null-safety
Extension functions and properties on nullable:
“car” is
nullable
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
16
Type inference
“car car = new car”
“car entity repository car entity repository = new car entity repository”



we live in the world of redundancy
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
17
Type inference
If it is apparent, why repeat?
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
18
Type inference
And if it is non-default, then specify it:
(not redundant)
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
19
Type inference
Not only variables and properties, return types too:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
20
Type inference
No type inference for function arguments

(because compiler will become insanely slow)
(and your code insanely complicated)
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
21
Immutability by default
Variables, properties and collections
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
22
Immutability by default
“val” is preferred over “var”
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
23
Immutability by default
Collections don’t have modifying methods by default
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
24
Immutability by default
And you can make it mutable if you need it
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
25
Proper “==”
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
26
Named arguments and
default parameter values
Build your own light-weight DSLs
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
27
Named arguments
Object factory methods for your test suite where you
specify only things you care about
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
28
Default parameter values
Object factory methods for your test suite where you
specify only things you care about
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
29
Named arguments
When you want to pass them in order you want
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
30
Named arguments and
default parameter values
Find your own usage that improves readability
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
31
Boilerplate-less class
definitions
Less redundancy!
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
32
Boilerplate-less class
definitions
Short syntax for constructors
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
33
Boilerplate-less class
definitions
Short syntax for binding constructor parameters to
properties
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
34
Boilerplate-less class
definitions
Data classes for your DTOs
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
35
Boilerplate-less class
definitions
Data classes: “==” based on field values
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
36
Boilerplate-less class
definitions
Data classes: “.copy(…)” to create new instance and
modify only few fields:
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
37
Boilerplate-less class
definitions
Data classes: convenient “.toString()”
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
38
Boilerplate-less class
definitions
Data classes: convenient “.hashCode()”
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
39
Boilerplate-less class
definitions
Data classes: de-structuring
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
40
Boilerplate-less class
definitions
Properties: concisely define default getter and setter
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
41
Boilerplate-less class
definitions
Properties: separate visibility of getter & setter
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
42
Boilerplate-less class
definitions
Properties: custom implementation of getter/setter
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
43
Ever wished this other class
from standard lib had certain
method X?
With extension methods & properties now you can!
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
44
Extension methods
It’s like “monkey-patching” (from Ruby)

It’s like “adding method to prototype” (from JS)
but without negative consequences
you have to
import it where
used
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
45
Extension properties
When you want to make it feel like accessing a
property
ALT+ENTER auto-
import works here
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
46
Extension methods & props
• No global scope pollution
• They do not modify original classes
• They are basically a syntax sugar:
• Except that you can call them as methods/props
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
47
So much more we can talk about
proper function types
“it”
passed
lambdas look like
blocks
lambdas with
receiver for DSLs

+ infix functions
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
48
And more absolutely
amazing for SQL in your
repositories
stop treating
certain things as
exceptions (int, bool)
forgot to handle a
case for enum, use
exhaustive when
just what you want
from a singleton!
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
49
And more
Don’t try Kotlin on the Back-end or You’ll Get Hooked!
50
I’m covering all of that in:
iwillteachyoukotlin.com/newsletter
bit.ly/2MSsuZG
or
Thank you!
Questions & Answers

More Related Content

Similar to Dont Try Kotlin on The Backend or You'll Get Hooked

Similar to Dont Try Kotlin on The Backend or You'll Get Hooked (15)

Kotlin
KotlinKotlin
Kotlin
 
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
 
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor BuzatovićJavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
 
Kotlin Language powerpoint show file
Kotlin Language powerpoint show fileKotlin Language powerpoint show file
Kotlin Language powerpoint show file
 
Kotlin – Alternative oder Ergänzung zu Java?
Kotlin – Alternative oder Ergänzung zu Java?Kotlin – Alternative oder Ergänzung zu Java?
Kotlin – Alternative oder Ergänzung zu Java?
 
Power Up Your Build - Omer van Kloeten @ Wix 2018-04
Power Up Your Build - Omer van Kloeten @ Wix 2018-04Power Up Your Build - Omer van Kloeten @ Wix 2018-04
Power Up Your Build - Omer van Kloeten @ Wix 2018-04
 
Racing car katas Ⅲ - Static Cling
Racing car katas Ⅲ - Static ClingRacing car katas Ⅲ - Static Cling
Racing car katas Ⅲ - Static Cling
 
Kotlin 1.1
Kotlin 1.1Kotlin 1.1
Kotlin 1.1
 
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
TDC2017 | Florianopolis - Trilha DevOps How we figured out we had a SRE team ...
 
Getting started with Apache Camel - jDays 2013
Getting started with Apache Camel - jDays 2013Getting started with Apache Camel - jDays 2013
Getting started with Apache Camel - jDays 2013
 
vJUG24 - Spring Boot and Kotlin, a match made in Heaven
vJUG24 - Spring Boot and Kotlin, a match made in HeavenvJUG24 - Spring Boot and Kotlin, a match made in Heaven
vJUG24 - Spring Boot and Kotlin, a match made in Heaven
 
Principled And Clean Coding
Principled And Clean CodingPrincipled And Clean Coding
Principled And Clean Coding
 
QCon São Paulo 2018
QCon São Paulo 2018QCon São Paulo 2018
QCon São Paulo 2018
 
Atlassian Summit 2010 - award winning talk on innovative use of Eclipse / Myl...
Atlassian Summit 2010 - award winning talk on innovative use of Eclipse / Myl...Atlassian Summit 2010 - award winning talk on innovative use of Eclipse / Myl...
Atlassian Summit 2010 - award winning talk on innovative use of Eclipse / Myl...
 
Cpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp EuropeCpp Testing Techniques Tips and Tricks - Cpp Europe
Cpp Testing Techniques Tips and Tricks - Cpp Europe
 

Recently uploaded

Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
Abortion Pill Prices Boksburg [(+27832195400*)] 🏥 Women's Abortion Clinic in ...
 
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & InnovationWSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
WSO2CON 2024 - OSU & WSO2: A Decade Journey in Integration & Innovation
 
WSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid EnvironmentsWSO2Con2024 - Software Delivery in Hybrid Environments
WSO2Con2024 - Software Delivery in Hybrid Environments
 
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
WSO2CON 2024 - Unlocking the Identity: Embracing CIAM 2.0 for a Competitive A...
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
WSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security ProgramWSO2CON 2024 - How to Run a Security Program
WSO2CON 2024 - How to Run a Security Program
 
WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next IntegrationWSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
WSO2CON2024 - Why Should You Consider Ballerina for Your Next Integration
 
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million PeopleWSO2Con2024 - Unleashing the Financial Potential of 13 Million People
WSO2Con2024 - Unleashing the Financial Potential of 13 Million People
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
WSO2CON 2024 - Not Just Microservices: Rightsize Your Services!
 
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With SimplicityWSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
WSO2Con2024 - Enabling Transactional System's Exponential Growth With Simplicity
 
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
WSO2CON 2024 - IoT Needs CIAM: The Importance of Centralized IAM in a Growing...
 
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
WSO2Con2024 - From Code To Cloud: Fast Track Your Cloud Native Journey with C...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
WSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital BusinessesWSO2CON 2024 - Software Engineering for Digital Businesses
WSO2CON 2024 - Software Engineering for Digital Businesses
 
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
WSO2Con2024 - Navigating the Digital Landscape: Transforming Healthcare with ...
 

Dont Try Kotlin on The Backend or You'll Get Hooked

  • 1. Don’t try Kotlin
 on the Back-end or
 You’ll Get Hooked! by Oleksii Fedorov
  • 2. Don’t try Kotlin on the Back-end or You’ll Get Hooked! Who am I? Oleksii Fedorov • Sr Software Engineer @ Pivotal Berlin • Entrepreneur In-house @ Pivotal Berlin • Founder @ iwillteachyoukotlin.com • Kotlin on Back-end in Production for 2+ years • Programming for more than 2/3 of my life • Writer, mentor, coach 2
  • 3. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 3 You don’t have to rewrite anything
  • 4. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 4 You don’t have to rewrite anything 1) Add tiny change to your Gradle/Maven build, e.g for Gradle:
  • 5. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 5 You don’t have to rewrite anything 2) Create your 1st Kotlin file, in same directory with Java files:
  • 6. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 6 You don’t have to rewrite anything 3) Use your Java (code and libs) from Kotlin, as if it was Kotlin:
  • 7. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 7 You don’t have to rewrite anything 4) Use your Kotlin (code and libs) from Java, as if it was Java:
  • 8. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 8 Barrier for entry is so low (so it’s almost a crime to not give it a shot)
  • 9. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 9 Great support on back-end • Spring (Boot) is fully supported (any recent version). And since Spring 5 (Boot 2) offers more concise Kotlinesque APIs • Vert.x provides dedicated Kotlin support • Ktor, specifically created for Kotlin, offers high scalability and easy-to-use idiomatic APIs • And virtually almost any JVM library
  • 10. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 10 Compile-time null-safety Compile error now > Runtime exception 1 year later
  • 11. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 11 Compile-time null-safety Compiler forces you to handle possible null value:
  • 12. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 12 Compile-time null-safety Instead of “if” statement, leverage safe calls:
  • 13. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 13 Compile-time null-safety Handle edge cases with Elvis operator
  • 14. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 14 Compile-time null-safety Thank you to Kotlin team for Smart-casting: as opposed to:
  • 15. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 15 Compile-time null-safety Extension functions and properties on nullable: “car” is nullable
  • 16. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 16 Type inference “car car = new car” “car entity repository car entity repository = new car entity repository”
 
 we live in the world of redundancy
  • 17. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 17 Type inference If it is apparent, why repeat?
  • 18. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 18 Type inference And if it is non-default, then specify it: (not redundant)
  • 19. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 19 Type inference Not only variables and properties, return types too:
  • 20. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 20 Type inference No type inference for function arguments
 (because compiler will become insanely slow) (and your code insanely complicated)
  • 21. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 21 Immutability by default Variables, properties and collections
  • 22. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 22 Immutability by default “val” is preferred over “var”
  • 23. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 23 Immutability by default Collections don’t have modifying methods by default
  • 24. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 24 Immutability by default And you can make it mutable if you need it
  • 25. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 25 Proper “==”
  • 26. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 26 Named arguments and default parameter values Build your own light-weight DSLs
  • 27. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 27 Named arguments Object factory methods for your test suite where you specify only things you care about
  • 28. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 28 Default parameter values Object factory methods for your test suite where you specify only things you care about
  • 29. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 29 Named arguments When you want to pass them in order you want
  • 30. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 30 Named arguments and default parameter values Find your own usage that improves readability
  • 31. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 31 Boilerplate-less class definitions Less redundancy!
  • 32. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 32 Boilerplate-less class definitions Short syntax for constructors
  • 33. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 33 Boilerplate-less class definitions Short syntax for binding constructor parameters to properties
  • 34. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 34 Boilerplate-less class definitions Data classes for your DTOs
  • 35. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 35 Boilerplate-less class definitions Data classes: “==” based on field values
  • 36. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 36 Boilerplate-less class definitions Data classes: “.copy(…)” to create new instance and modify only few fields:
  • 37. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 37 Boilerplate-less class definitions Data classes: convenient “.toString()”
  • 38. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 38 Boilerplate-less class definitions Data classes: convenient “.hashCode()”
  • 39. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 39 Boilerplate-less class definitions Data classes: de-structuring
  • 40. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 40 Boilerplate-less class definitions Properties: concisely define default getter and setter
  • 41. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 41 Boilerplate-less class definitions Properties: separate visibility of getter & setter
  • 42. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 42 Boilerplate-less class definitions Properties: custom implementation of getter/setter
  • 43. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 43 Ever wished this other class from standard lib had certain method X? With extension methods & properties now you can!
  • 44. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 44 Extension methods It’s like “monkey-patching” (from Ruby)
 It’s like “adding method to prototype” (from JS) but without negative consequences you have to import it where used
  • 45. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 45 Extension properties When you want to make it feel like accessing a property ALT+ENTER auto- import works here
  • 46. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 46 Extension methods & props • No global scope pollution • They do not modify original classes • They are basically a syntax sugar: • Except that you can call them as methods/props
  • 47. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 47 So much more we can talk about proper function types “it” passed lambdas look like blocks lambdas with receiver for DSLs
 + infix functions
  • 48. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 48 And more absolutely amazing for SQL in your repositories stop treating certain things as exceptions (int, bool) forgot to handle a case for enum, use exhaustive when just what you want from a singleton!
  • 49. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 49 And more
  • 50. Don’t try Kotlin on the Back-end or You’ll Get Hooked! 50 I’m covering all of that in: iwillteachyoukotlin.com/newsletter bit.ly/2MSsuZG or Thank you! Questions & Answers