3. 3
Shaping the
future of digital
business
gft.com
Agenda
1. Krótko o Kotinie
2. Podstawy
3. Przydatne ficzery
4. Kotlin i programowanie funkcyjne
5. Jak dodać Kotlin do projektu
6. Aplikacja Spring Boot w Kotlinie vs Java
7. Kotlin w GFT
8. Q&A
4. 4
Shaping the
future of digital
business
gft.com
Kotlin?
Kotlin jest językiem programowania ogólnego przeznaczenia, który czyni developerów szczęśliwszym.
Open source na zawsze.
Dobry do:
Mobile cross-platform
Server-side
Native
Web development
Data science
Android
5. 5
Shaping the
future of digital
business
gft.com
Krótka historia Kotlina
2010 - początki prac nad Kotlinem
02.2012 - Kotlin został otwarty na licencji Apache 2
02.2016 - Kotlin 1.0 - pierwszy oficjalny release
05.2017 - Google ogłasza wsparcie Kotlina na Androidzie
11.2017 - Kotlin 1.2 - wsparcie dla JS
10.2018 - Kotlin 1.3 - Coroutines - programowanie asynchroniczne
05.2019 - Google ogłasza Kotlin preferowanym językiem na Androida
6. 6
Shaping the
future of digital
business
gft.com
Kto i dlaczego?
Kto?
JetBrains - autorzy IntelliJ, WebStorm, PyCharm
Dlaczego?
“Większośc języków nie ma ficzerów, których szukamy, za wyjątkiem Scali. Scala z kolei kompiluje
się bardzo wolno, dlatego chcemy żeby Kotlin kompilował się równie szybko, co Java.”
8. 8
Shaping the
future of digital
business
gft.com
Java vs Kotlin
Dlaczego Kotlin?
zwięzła składnia - średnio o 40% mniej linii kodu
szybciej się w nim pisze
lepsze wsparcie dla programowania funkcyjnego
czytelna składnia - mniej boilerplate
przydatne ficzery - smart cast, extension functions i wiele innych
brak checked exceptions
wieloplatformowy - JVM, native, JS, Data Science, Android, multiplatform
kompatybilny z bibliotekami Javy
100% współpracuje z Javą
9. 9
Shaping the
future of digital
business
gft.com
Basics - variables
val - immutable variable
var - mutable variable
inferred type
top level variables
comments
10. 10
Shaping the
future of digital
business
gft.com
Basics - functions
entry point
functions
default parameters
inferred return type
Unit return type
function calls
named parameters
omit default parameters
11. 11
Shaping the
future of digital
business
gft.com
Basics - classes
constructor
getters
setters
val vs var
secondary constructor
12. 12
Shaping the
future of digital
business
gft.com
Basics - classes inheritance
Each class inherits from Any
Any has three methods:
equals()
hashCode()
toString()
class has to be open
explicit override
interfaces
abstract classes
13. 13
Shaping the
future of digital
business
gft.com
Basics - strings and ifs
String templates
use variables
use expressions
If block
short syntax
is an expression
14. 14
Shaping the
future of digital
business
gft.com
Basics - objects and properties
no new keyword
. access calls getters and setters
explicit getter and setter
there is a lot more
15. 15
Shaping the
future of digital
business
gft.com
Basics - loops and when
for loop
while loop
when expression
expression or statement
multiple cases in one branch
use expressions
us is check
16. 16
Shaping the
future of digital
business
gft.com
Useful features - smart casting
is operator
automatic cast to type
… in block scope
… in expression scope
17. 17
Shaping the
future of digital
business
gft.com
Useful features - ranges
check if number in range
check if number out of range
iterate over range
iterate over progression
18. 18
Shaping the
future of digital
business
gft.com
Useful features - nullable types
nullable types
null checks at compilation
time
safe calls required for
nullable variables
19. 19
Shaping the
future of digital
business
gft.com
Useful features - safe calls and operators
?:
Elvis Operator
21. 21
Shaping the
future of digital
business
gft.com
Useful features - extension functions
add function to any class
even external closed APIs
we can add functionality to closed classes
22. 22
Shaping the
future of digital
business
gft.com
Functional programming
functions as first class citizens
use functions as building blocks
immutable data
pure functions
function as a type
higher order functions
anonymous functions
26. 26
Shaping the
future of digital
business
gft.com
Jest tego o wiele więcej
delegate properties
coroutines
immutable collections
singletons
list, dict and set comprehension
destructuring
utility function - run(), let(), with()
data classes
...
27. 27
Shaping the
future of digital
business
gft.com
Jak dodać Kotlin do projektu?
Add and configure Kotlin Maven Plugin:
Hibernate - https://kotlinexpertise.com/hibernate-with-kotlin-spring-boot/
39. 39
Shaping the
future of digital
business
gft.com
GFT & Kotlin
Wirtualny bank budowany od zera
ponad 200 deweloperów z całego świata, w tym 50 osób z GFT
MIkroserwisy 100% napisane w Kotlin ze Spring Boot
80 mikroserwisów - klaster Kubernetes
integracja mikroserwisów poprzez REST i Kafkę
Contract First - OPEN API 3
DDD i CQRS
cloud native - AWS
A to tylko jeden z naszych projektów, w którym używamy Kotlina.
41. 41
Shaping the
future of digital
business
gft.com
Linki
Kotlin page: https://kotlinlang.org/
Try Kotlin: https://try.kotlinlang.org/
Jetbrains Academy: https://www.jetbrains.com/academy/
Kotlin for Java Developers: https://www.coursera.org/learn/kotlin-for-java-developers
Add Kotlin to your project: https://www.baeldung.com/kotlin-maven-java-project