SlideShare una empresa de Scribd logo
1 de 70
Descargar para leer sin conexión
otlin meets Gadsu
Christoph Pickl
Kotlin Vienna Meetup – 2017-01-31
Agenda
1 Introduction to Gadsu
2 Kotlin in the wild
3 Code “Schmankerln”
4 Lessons Learned
2
Introduction to Gadsu
This is a cat.
4
This is Shiatsu . . .
5
. . . so is this.
6
Gadsu is . . .
Gadse
+ Shiatsu
= Gadsu
7
Shiatsu is . . .
. . . Japanese! Food! Yam yam!
8
Shiatsu is . . .
Massage, Physiotherapy, Bodywork
Acupuncture, Meridiantherapy
Nervous system stimulation
Based on the Traditional Chinese Medicine
Concept of Qi flowing through the body and everything
Body and mind seen as a unit, not separated from each other
Taiji Symbol, Theory of Yin and Yang
9
Gadsu can . . .
Features:
Client database
Manage medical records
Generate reports
Google integration
Auto update, auto backup
Roadmap:
Pain indicator, 5 Elements
Statistics
TCM intelligence
Doodle integration
Invoicing
10
Technology Stack
Gradle
Swing
Guice
Spring JDBC, HSQLDB, Flyway
Jasper, Pdfbox, Freemarker
TestNG, Mockito, Hamcrest, UISpec4J
Initial implementation used Kotlin 0.6 ; )
11
Gadsu got something like 30,000 LoC :)
12
Let’s see some app . . .
13
otlin in the wild
build.gradle
1 apply plugin: "kotlin"
2 buildscript {
3 ext.kotlin_version = ’1.0.6 ’
4 dependencies {
5 classpath "org.jetbrains.kotlin:
6 kotlin -gradle -plugin: $kotlin_version "
7 }
8 }
9 dependencies {
10 compile "org.jetbrains.kotlin:
11 kotlin -stdlib: $kotlin_version "
12 compile "org.jetbrains.kotlin:
13 kotlin -reflect: $kotlin_version "
14 }
15
travis-ci.org
16
.travis.yml
1 language: kotlin
2 sudo: false
3 jdk:
4 - oraclejdk8
5 before_install:
6 - "chmod +x gradlew"
7 - "export DISPLAY =:99.0"
8 - "sh -e /etc/init.d/xvfb start"
9 script:
10 - "./ gradlew test ..."
11 notifications:
12 email:
13 - "MLtravis@gadsu .com"
17
codecov.io
18
Codecov
Gradle Configuration:
1 plugins {
2 id ’jacoco ’
3 id ’com.github.kt3k.coveralls ’
4 }
5 jacocoTestReport {
6 reports {
7 xml.enabled = true
8 }}
Travis Configuration:
1 script:
2 - "./ gradlew ... jacocoTestReport ..."
3 after_success:
4 - bash <(curl -s https:// codecov.io/bash)
19
VersionEye GitHub Integration
Display coverage data via the Codecov Browser Extension:
20
versioneye.com
21
VersionEye
Gradle Configuration:
1 plugins {
2 id "org.standardout.versioneye"
3 version "1.4.0"
4 }
Gradle Properties:
1 versioneye.projectid =572880644 a0f ...00 b78206
Travis Configuration:
1 script:
2 - "./ gradlew ... versioneye -update ..."
22
Code Schmankerln
Null Handling
24
Trust no one!
1 @Data
2 class Contact {
3 String mail;
4 }
5 @Data
6 class Client {
7 Contact contact;
8 public boolean hasContact () {
9 return contact != null;
10 }
11 }
12
13 if (client.hasContact ()) {
14 process(client.getContact ());
15 }
25
Explicit handling in Kotlin
1 data class Contact(val mail: String)
2 data class Client(val contact: Contact ?)
3
4 client.contact.ifNotNull (:: process)
5 client.contact ?. mail ?: "default@mail.at"
Write your own, custom if-loop:
1 fun <T> T?. ifNotNull(action: (T) -> Unit ):
2 T? {
3 if (this == null) {
4 return null
5 }
6 action(this)
7 return this
8 }
26
Extension Methods
27
Domain Object
Implement a straight-forward, clean domain object:
1 package at.cpickl.gadsu.client
2
3 data class Client(
4 val id: String ,
5 val name: String
6 )
28
Persistence Extensions
Persistence specific functionality:
1 package at.cpickl.gadsu.persistence
2
3 data class ClientDbo(
4 val TXT_ID: String ,
5 val TXT_NAME: String
6 )
7 fun Client.toDbo () =
8 ClientDbo(id , name)
9
10 class ClientRepo {
11 fun save(client: Client) {
12 saveSomewhere(client.toDbo ())
13 }
14 }
29
Nullable Persistence Extensions
Or for those masochists out there who prefer nullables:
1 package at.cpickl.gadsu.persistence
2
3 fun Client ?. toDbo () =
4 if (this == null) null
5 else ClientDbo(id , name)
6
7 val client: Client? = ....
8 val dbo = client.toDbo ()
9 ?: ClientDbo. defaultInstance ()
30
Extend Swing Components
Add a fluent API to an existing classes:
1 fun <T : JComponent > T.bold (): T {
2 font = font.deriveFont(Font.BOLD)
3 return this
4 }
5
6 val myLabel = JLabel("text"). bold (). italic ()
7 val myTextField = JTextField("text"). bold ()
8 val myTextArea = JTextArea("text"). bold ()
9
10 val panel = JPanel (). transparent ()
31
Extension Properties
32
Testee Properties
Possible replacement of common test factories:
1 package at.cpickl.gadsu.test
2
3 val Client.Companion.testee1: Client
4 get() = Client(
5 id = "",
6 name = "Max Muster"
7 )
Unfortunately Kotlin requires to have some placeholder:
1 package at.cpickl.gadsu.client
2
3 data class Client( ... ) {
4 companion object {}
5 }
33
Integration Testee
Use those testees in your tests:
1 package at.cpickl.gadsu.test
2
3 @Test class ClientIT {
4
5 @Inject lateinit var repo: ClientRepo
6
7 fun ‘reference test scoped testee ‘() {
8 repo.save(
9 Client.testee1.copy(name = "Otto")
10 )
11 // ... assertions ...
12 }
13 }
34
λ
35
Functional done right!
Java 8 being veeery verbose as always:
1 List <Integer > numbers = asList (1, 2, 3);
2 List <String > numbers2 = numbers
3 .stream ()
4 .filter(i -> i % 2 == 0)
5 .map(Object :: toString)
6 .collect(toList ());
Kotlin (implicit it variable)
1 val numbers = listOf (1, 2, 3)
2 val numbers2 = numbers
3 .filter { it % 2 == 0 }
4 .map(Int:: toString)
36
Java sometimes behaves like good old Aunt Chatty.
37
Kotlin Basic Functionals?!
fun <T, R> T.let(f: (T) -> R): R =
f(this)
fun <T> T.apply(f: T.() -> Unit): T
{ f(); return this }
fun <T, R> with(receiver: T, f: T.() -> R): R =
receiver.f()
fun <T, R> T.run(f: T.() -> R): R =
f()
38
Sometimes I feel so lazy . . .
39
Lazy in Java
Given there is a very expensive expensiveInit() method:
1 public class NaiveSingleton {
2 private Object lazyField = null;
3
4 public Object getLazyField () {
5 if (lazyField == null) {
6 lazyField = expensiveInit ();
7 }
8 return lazyField;
9 }
10 }
40
Lazy in Java8
1 public class Java8 {
2 private Supplier <Object > lazyField =() -> {
3 Object value = expensiveInit ();
4 lazyField = () -> value;
5 return value;
6 };
7
8 public Object getLazyField () {
9 return lazyField.get ();
10 }
11 }
41
Lazy in Kotlin
1 class LazyKotlin {
2 val lazyField by lazy {
3 expensiveInit ()
4 }
5 }
6
7 // part of stdlib:
8 fun <T> lazy(initializer: ()->T): Lazy <T> =
9 SynchronizedLazyImpl (initializer)
Thanks to type inference, we don’t need to specify types explicity.
42
Delegates
43
Class Delegation
Given the existing classes:
1 interface Step {
2 fun take ()
3 }
4
5 class StepImpl : Step {
6 override fun take () {}
7 }
We now want some new service to implement this interface,
but delegate all its methods to the StepImpl implementation.
44
Reimplement in Java
1 public class MyService implements Step {
2
3 private final Step step;
4
5 public MyService(Step step) {
6 this.step = step;
7 }
8
9 @Override public void take () {
10 step.take ();
11 }
12 }
45
Delegate by Kotlin
1 class MyService(step: Step) : Step by step
Standard delegates in Kotlin:
lazy
observable
map properties
46
Let’s do the Swing!
47
Common Swing Component
1 class ClientTabMain(modifications , ...) {
2 val fields = Fields <Client >( modifications)
3 val inpNote = fields.newTextArea(
4 "Notiz", { it.note },
5 ViewNames.Client.InputNote , bus)
6 init {
7 add(VFillFormPanel (). apply {
8 addFormInput(inpNote)
9 })}
10 fun isModified(client: Client) =
11 fields.isAnyModified(client)
12 fun updateFields(client: Client) {
13 fields.updateAll(client)
14 }
15 }
48
Event Driven Swing
Dispatch events via EventBus and subscribe in Controller:
1 open class ClientViewController @Inject
2 constructor(val bus: EventBus , ...) {
3
4 @Subscribe open fun onAppStartupEvent (
5 event: AppStartupEvent ) {
6 reinitClients ()
7 bus.post( ChangeMainContentEvent (view ))
8 ...
49
Spec4J UI Test
1 @Test(groups = arrayOf("uiTest"))
2 class ClientUiTest : UiTest () {
3 fun ‘save client should change UI ‘() {
4 val client = Client. unsavedValidInstance ()
5 with(driver) {
6 assertSaveButtonTextEquals ("Neu anlegen")
7
8 saveClient(client)
9 assertSaveButtonTextEquals ("Speichern")
10
11 assertListContains (client)
12 assertListSelected (client)
13 ...
50
Spec4J UI Driver
1 class ClientDriver(
2 test: UiTest , window: Window) {
3
4 val list = window.getListBox(
5 ViewNames.Client.List )!!
6 val createButton = window.getButton(
7 ViewNames.Client.CreateButton )!!
8
9 fun assertNoChangesDetected () {
10 test.assertThat(
11 test.not(saveButton.isEnabled ))
12 test.assertThat(
13 test.not(cancelButton.isEnabled ))
14 }
15 ...
51
Lessons Learned
Tooling infrastructure grows
Mostly as good as for Java
IntelliJ support feels already superb
Build system support (Gradle Script Kotlin!)
Static code analysis tools missing
Syntax highlighting mostly missing
53
8 reasons to use Kotlin
1 Null handling is a MUST!
54
Remember me?!
55
8 reasons to use Kotlin
1 Null handling is a MUST!
2 Extension methods for improved auto completion
3 (Constructor) Properties
4 Lambdas done properly
5 (Local) Type inference
6 Named and default arguments
7 Compact syntax: No semicolon, new
8 Data classes replaces Lombok
56
Kotlin is a great language . . . BUT!
Data classes are still somehow restricted in their usage (v1.1)
Paradigm shift of final-by-default clashes with existing libs
Requires young padawan to be more disciplined
Several classes in one (big) file gets common
Explicit type declaration for documentation
Overuse of single-expression functions
Overuse of functionals like apply{}
57
Apply – Who is this?
1 class MainPanel : JPanel () {
2 init {
3 val subPanel = JPanel ()
4 subPanel.background = Color.RED
5 add(subPanel)
6 }
7 }
We can refactor this to get rid of the variable reference.
58
Apply – This is not this anymore!
1 class MainPanel : JPanel () {
2 init {
3 JPanel (). apply {
4 background = Color.RED
5 add(this)
6 }
7 }
8 }
IllegalArgumentException: adding container’s parent to itself
The solution is to use: this@MainPanel.add(this)
But what happens if there are two nested JPanels?!
PS: Kotlin 1.1 will come with a new function called also()
1 JPanel (). also {
2 this.add(it)
3 }
59
11 Kotlin 1.1 News
1 Compiler plugins (open-by-default, no-arg ctor)
2 Coroutines
3 Type aliases
4 Type inference for getters
5 Bound callable references
6 Local delegated properties & Inline properties
7 Inheritance for data classes
8 Subclasses of sealed classes in the same file
9 Destructuring in lambdas
10 Underscore for unused parameters
11 Underscore in numeric literals
60
Links
Visit Gadsu website:
https://github.com/christophpickl/gadsu
LATEX sources of slides:
https://github.com/christophpickl/gadsu meetup
Kotlin Vienna Meetup:
https://www.meetup.com/Kotlin-Vienna
Kotlin Slack Channel:
https://kotlinlang.slack.com/messages/vienna/
61
One more thing . . .
62
63
64
65
66
67
68
69
70

Más contenido relacionado

La actualidad más candente

Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...julien.ponge
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydneyjulien.ponge
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30Mahmoud Samir Fayed
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleAnton Arhipov
 
Java 7 at SoftShake 2011
Java 7 at SoftShake 2011Java 7 at SoftShake 2011
Java 7 at SoftShake 2011julien.ponge
 
Java 7 JUG Summer Camp
Java 7 JUG Summer CampJava 7 JUG Summer Camp
Java 7 JUG Summer Campjulien.ponge
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Anton Arhipov
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехСбертех | SberTech
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency IdiomsAlex Miller
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingAnton Arhipov
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarROHIT JAISWAR
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Victor_Cr
 
Understanding Java byte code and the class file format
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file formatRafael Winterhalter
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEUehara Junji
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Davide Cerbo
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Arnaud Giuliani
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Uehara Junji
 

La actualidad más candente (20)

Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
 
Java 7 LavaJUG
Java 7 LavaJUGJava 7 LavaJUG
Java 7 LavaJUG
 
Software Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW SydneySoftware Testing - Invited Lecture at UNSW Sydney
Software Testing - Invited Lecture at UNSW Sydney
 
Unit testing concurrent code
Unit testing concurrent codeUnit testing concurrent code
Unit testing concurrent code
 
Migrating to JUnit 5
Migrating to JUnit 5Migrating to JUnit 5
Migrating to JUnit 5
 
The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30The Ring programming language version 1.4 book - Part 3 of 30
The Ring programming language version 1.4 book - Part 3 of 30
 
GeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassleGeeCON 2017 - TestContainers. Integration testing without the hassle
GeeCON 2017 - TestContainers. Integration testing without the hassle
 
Java 7 at SoftShake 2011
Java 7 at SoftShake 2011Java 7 at SoftShake 2011
Java 7 at SoftShake 2011
 
Java 7 JUG Summer Camp
Java 7 JUG Summer CampJava 7 JUG Summer Camp
Java 7 JUG Summer Camp
 
Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011Java Bytecode for Discriminating Developers - JavaZone 2011
Java Bytecode for Discriminating Developers - JavaZone 2011
 
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТехБоремся с NPE вместе с Kotlin, Павел Шацких СберТех
Боремся с NPE вместе с Kotlin, Павел Шацких СберТех
 
Java Concurrency Idioms
Java Concurrency IdiomsJava Concurrency Idioms
Java Concurrency Idioms
 
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloadingJEEConf 2017 - The hitchhiker’s guide to Java class reloading
JEEConf 2017 - The hitchhiker’s guide to Java class reloading
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"Club of anonimous developers "Refactoring: Legacy code"
Club of anonimous developers "Refactoring: Legacy code"
 
Understanding Java byte code and the class file format
Understanding Java byte code and the class file formatUnderstanding Java byte code and the class file format
Understanding Java byte code and the class file format
 
Easy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVEEasy Going Groovy 2nd season on DevLOVE
Easy Going Groovy 2nd season on DevLOVE
 
Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)Kotlin: forse è la volta buona (Trento)
Kotlin: forse è la volta buona (Trento)
 
Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017Kotlin hands on - MorningTech ekito 2017
Kotlin hands on - MorningTech ekito 2017
 
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
Let's go Developer 2011 sendai Let's go Java Developer (Programming Language ...
 

Similar a Kotlin meets Gadsu

Python and cassandra
Python and cassandraPython and cassandra
Python and cassandraJon Haddad
 
Cassandra Day Atlanta 2015: Python & Cassandra
Cassandra Day Atlanta 2015: Python & CassandraCassandra Day Atlanta 2015: Python & Cassandra
Cassandra Day Atlanta 2015: Python & CassandraDataStax Academy
 
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180Mahmoud Samir Fayed
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?Andrey Karpov
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and ClassesIntro C# Book
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0William Munn
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42Yevhen Bobrov
 
The Ring programming language version 1.10 book - Part 12 of 212
The Ring programming language version 1.10 book - Part 12 of 212The Ring programming language version 1.10 book - Part 12 of 212
The Ring programming language version 1.10 book - Part 12 of 212Mahmoud Samir Fayed
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The LandingHaci Murat Yaman
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lispelliando dias
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210Mahmoud Samir Fayed
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent codeDror Helper
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMERAndrey Karpov
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?intelliyole
 

Similar a Kotlin meets Gadsu (20)

Python and cassandra
Python and cassandraPython and cassandra
Python and cassandra
 
Cassandra Day Atlanta 2015: Python & Cassandra
Cassandra Day Atlanta 2015: Python & CassandraCassandra Day Atlanta 2015: Python & Cassandra
Cassandra Day Atlanta 2015: Python & Cassandra
 
The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180The Ring programming language version 1.5.1 book - Part 12 of 180
The Ring programming language version 1.5.1 book - Part 12 of 180
 
00_Introduction to Java.ppt
00_Introduction to Java.ppt00_Introduction to Java.ppt
00_Introduction to Java.ppt
 
Static code analysis: what? how? why?
Static code analysis: what? how? why?Static code analysis: what? how? why?
Static code analysis: what? how? why?
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
Legacy Code Kata v3.0
Legacy Code Kata v3.0Legacy Code Kata v3.0
Legacy Code Kata v3.0
 
The uniform interface is 42
The uniform interface is 42The uniform interface is 42
The uniform interface is 42
 
The Ring programming language version 1.10 book - Part 12 of 212
The Ring programming language version 1.10 book - Part 12 of 212The Ring programming language version 1.10 book - Part 12 of 212
The Ring programming language version 1.10 book - Part 12 of 212
 
How to fake_properly
How to fake_properlyHow to fake_properly
How to fake_properly
 
Node.js System: The Landing
Node.js System: The LandingNode.js System: The Landing
Node.js System: The Landing
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210The Ring programming language version 1.9 book - Part 99 of 210
The Ring programming language version 1.9 book - Part 99 of 210
 
Scala to assembly
Scala to assemblyScala to assembly
Scala to assembly
 
Celery with python
Celery with pythonCelery with python
Celery with python
 
Data herding
Data herdingData herding
Data herding
 
Data herding
Data herdingData herding
Data herding
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
 
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMEREVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
EVERYTHING ABOUT STATIC CODE ANALYSIS FOR A JAVA PROGRAMMER
 
Kotlin: Why Do You Care?
Kotlin: Why Do You Care?Kotlin: Why Do You Care?
Kotlin: Why Do You Care?
 

Último

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
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.
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Último (20)

Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female serviceCALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
CALL ON ➥8923113531 🔝Call Girls Badshah Nagar Lucknow best Female service
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
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 ...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Kotlin meets Gadsu

  • 1. otlin meets Gadsu Christoph Pickl Kotlin Vienna Meetup – 2017-01-31
  • 2. Agenda 1 Introduction to Gadsu 2 Kotlin in the wild 3 Code “Schmankerln” 4 Lessons Learned 2
  • 4. This is a cat. 4
  • 5. This is Shiatsu . . . 5
  • 6. . . . so is this. 6
  • 7. Gadsu is . . . Gadse + Shiatsu = Gadsu 7
  • 8. Shiatsu is . . . . . . Japanese! Food! Yam yam! 8
  • 9. Shiatsu is . . . Massage, Physiotherapy, Bodywork Acupuncture, Meridiantherapy Nervous system stimulation Based on the Traditional Chinese Medicine Concept of Qi flowing through the body and everything Body and mind seen as a unit, not separated from each other Taiji Symbol, Theory of Yin and Yang 9
  • 10. Gadsu can . . . Features: Client database Manage medical records Generate reports Google integration Auto update, auto backup Roadmap: Pain indicator, 5 Elements Statistics TCM intelligence Doodle integration Invoicing 10
  • 11. Technology Stack Gradle Swing Guice Spring JDBC, HSQLDB, Flyway Jasper, Pdfbox, Freemarker TestNG, Mockito, Hamcrest, UISpec4J Initial implementation used Kotlin 0.6 ; ) 11
  • 12. Gadsu got something like 30,000 LoC :) 12
  • 13. Let’s see some app . . . 13
  • 14. otlin in the wild
  • 15. build.gradle 1 apply plugin: "kotlin" 2 buildscript { 3 ext.kotlin_version = ’1.0.6 ’ 4 dependencies { 5 classpath "org.jetbrains.kotlin: 6 kotlin -gradle -plugin: $kotlin_version " 7 } 8 } 9 dependencies { 10 compile "org.jetbrains.kotlin: 11 kotlin -stdlib: $kotlin_version " 12 compile "org.jetbrains.kotlin: 13 kotlin -reflect: $kotlin_version " 14 } 15
  • 17. .travis.yml 1 language: kotlin 2 sudo: false 3 jdk: 4 - oraclejdk8 5 before_install: 6 - "chmod +x gradlew" 7 - "export DISPLAY =:99.0" 8 - "sh -e /etc/init.d/xvfb start" 9 script: 10 - "./ gradlew test ..." 11 notifications: 12 email: 13 - "MLtravis@gadsu .com" 17
  • 19. Codecov Gradle Configuration: 1 plugins { 2 id ’jacoco ’ 3 id ’com.github.kt3k.coveralls ’ 4 } 5 jacocoTestReport { 6 reports { 7 xml.enabled = true 8 }} Travis Configuration: 1 script: 2 - "./ gradlew ... jacocoTestReport ..." 3 after_success: 4 - bash <(curl -s https:// codecov.io/bash) 19
  • 20. VersionEye GitHub Integration Display coverage data via the Codecov Browser Extension: 20
  • 22. VersionEye Gradle Configuration: 1 plugins { 2 id "org.standardout.versioneye" 3 version "1.4.0" 4 } Gradle Properties: 1 versioneye.projectid =572880644 a0f ...00 b78206 Travis Configuration: 1 script: 2 - "./ gradlew ... versioneye -update ..." 22
  • 25. Trust no one! 1 @Data 2 class Contact { 3 String mail; 4 } 5 @Data 6 class Client { 7 Contact contact; 8 public boolean hasContact () { 9 return contact != null; 10 } 11 } 12 13 if (client.hasContact ()) { 14 process(client.getContact ()); 15 } 25
  • 26. Explicit handling in Kotlin 1 data class Contact(val mail: String) 2 data class Client(val contact: Contact ?) 3 4 client.contact.ifNotNull (:: process) 5 client.contact ?. mail ?: "default@mail.at" Write your own, custom if-loop: 1 fun <T> T?. ifNotNull(action: (T) -> Unit ): 2 T? { 3 if (this == null) { 4 return null 5 } 6 action(this) 7 return this 8 } 26
  • 28. Domain Object Implement a straight-forward, clean domain object: 1 package at.cpickl.gadsu.client 2 3 data class Client( 4 val id: String , 5 val name: String 6 ) 28
  • 29. Persistence Extensions Persistence specific functionality: 1 package at.cpickl.gadsu.persistence 2 3 data class ClientDbo( 4 val TXT_ID: String , 5 val TXT_NAME: String 6 ) 7 fun Client.toDbo () = 8 ClientDbo(id , name) 9 10 class ClientRepo { 11 fun save(client: Client) { 12 saveSomewhere(client.toDbo ()) 13 } 14 } 29
  • 30. Nullable Persistence Extensions Or for those masochists out there who prefer nullables: 1 package at.cpickl.gadsu.persistence 2 3 fun Client ?. toDbo () = 4 if (this == null) null 5 else ClientDbo(id , name) 6 7 val client: Client? = .... 8 val dbo = client.toDbo () 9 ?: ClientDbo. defaultInstance () 30
  • 31. Extend Swing Components Add a fluent API to an existing classes: 1 fun <T : JComponent > T.bold (): T { 2 font = font.deriveFont(Font.BOLD) 3 return this 4 } 5 6 val myLabel = JLabel("text"). bold (). italic () 7 val myTextField = JTextField("text"). bold () 8 val myTextArea = JTextArea("text"). bold () 9 10 val panel = JPanel (). transparent () 31
  • 33. Testee Properties Possible replacement of common test factories: 1 package at.cpickl.gadsu.test 2 3 val Client.Companion.testee1: Client 4 get() = Client( 5 id = "", 6 name = "Max Muster" 7 ) Unfortunately Kotlin requires to have some placeholder: 1 package at.cpickl.gadsu.client 2 3 data class Client( ... ) { 4 companion object {} 5 } 33
  • 34. Integration Testee Use those testees in your tests: 1 package at.cpickl.gadsu.test 2 3 @Test class ClientIT { 4 5 @Inject lateinit var repo: ClientRepo 6 7 fun ‘reference test scoped testee ‘() { 8 repo.save( 9 Client.testee1.copy(name = "Otto") 10 ) 11 // ... assertions ... 12 } 13 } 34
  • 35. λ 35
  • 36. Functional done right! Java 8 being veeery verbose as always: 1 List <Integer > numbers = asList (1, 2, 3); 2 List <String > numbers2 = numbers 3 .stream () 4 .filter(i -> i % 2 == 0) 5 .map(Object :: toString) 6 .collect(toList ()); Kotlin (implicit it variable) 1 val numbers = listOf (1, 2, 3) 2 val numbers2 = numbers 3 .filter { it % 2 == 0 } 4 .map(Int:: toString) 36
  • 37. Java sometimes behaves like good old Aunt Chatty. 37
  • 38. Kotlin Basic Functionals?! fun <T, R> T.let(f: (T) -> R): R = f(this) fun <T> T.apply(f: T.() -> Unit): T { f(); return this } fun <T, R> with(receiver: T, f: T.() -> R): R = receiver.f() fun <T, R> T.run(f: T.() -> R): R = f() 38
  • 39. Sometimes I feel so lazy . . . 39
  • 40. Lazy in Java Given there is a very expensive expensiveInit() method: 1 public class NaiveSingleton { 2 private Object lazyField = null; 3 4 public Object getLazyField () { 5 if (lazyField == null) { 6 lazyField = expensiveInit (); 7 } 8 return lazyField; 9 } 10 } 40
  • 41. Lazy in Java8 1 public class Java8 { 2 private Supplier <Object > lazyField =() -> { 3 Object value = expensiveInit (); 4 lazyField = () -> value; 5 return value; 6 }; 7 8 public Object getLazyField () { 9 return lazyField.get (); 10 } 11 } 41
  • 42. Lazy in Kotlin 1 class LazyKotlin { 2 val lazyField by lazy { 3 expensiveInit () 4 } 5 } 6 7 // part of stdlib: 8 fun <T> lazy(initializer: ()->T): Lazy <T> = 9 SynchronizedLazyImpl (initializer) Thanks to type inference, we don’t need to specify types explicity. 42
  • 44. Class Delegation Given the existing classes: 1 interface Step { 2 fun take () 3 } 4 5 class StepImpl : Step { 6 override fun take () {} 7 } We now want some new service to implement this interface, but delegate all its methods to the StepImpl implementation. 44
  • 45. Reimplement in Java 1 public class MyService implements Step { 2 3 private final Step step; 4 5 public MyService(Step step) { 6 this.step = step; 7 } 8 9 @Override public void take () { 10 step.take (); 11 } 12 } 45
  • 46. Delegate by Kotlin 1 class MyService(step: Step) : Step by step Standard delegates in Kotlin: lazy observable map properties 46
  • 47. Let’s do the Swing! 47
  • 48. Common Swing Component 1 class ClientTabMain(modifications , ...) { 2 val fields = Fields <Client >( modifications) 3 val inpNote = fields.newTextArea( 4 "Notiz", { it.note }, 5 ViewNames.Client.InputNote , bus) 6 init { 7 add(VFillFormPanel (). apply { 8 addFormInput(inpNote) 9 })} 10 fun isModified(client: Client) = 11 fields.isAnyModified(client) 12 fun updateFields(client: Client) { 13 fields.updateAll(client) 14 } 15 } 48
  • 49. Event Driven Swing Dispatch events via EventBus and subscribe in Controller: 1 open class ClientViewController @Inject 2 constructor(val bus: EventBus , ...) { 3 4 @Subscribe open fun onAppStartupEvent ( 5 event: AppStartupEvent ) { 6 reinitClients () 7 bus.post( ChangeMainContentEvent (view )) 8 ... 49
  • 50. Spec4J UI Test 1 @Test(groups = arrayOf("uiTest")) 2 class ClientUiTest : UiTest () { 3 fun ‘save client should change UI ‘() { 4 val client = Client. unsavedValidInstance () 5 with(driver) { 6 assertSaveButtonTextEquals ("Neu anlegen") 7 8 saveClient(client) 9 assertSaveButtonTextEquals ("Speichern") 10 11 assertListContains (client) 12 assertListSelected (client) 13 ... 50
  • 51. Spec4J UI Driver 1 class ClientDriver( 2 test: UiTest , window: Window) { 3 4 val list = window.getListBox( 5 ViewNames.Client.List )!! 6 val createButton = window.getButton( 7 ViewNames.Client.CreateButton )!! 8 9 fun assertNoChangesDetected () { 10 test.assertThat( 11 test.not(saveButton.isEnabled )) 12 test.assertThat( 13 test.not(cancelButton.isEnabled )) 14 } 15 ... 51
  • 53. Tooling infrastructure grows Mostly as good as for Java IntelliJ support feels already superb Build system support (Gradle Script Kotlin!) Static code analysis tools missing Syntax highlighting mostly missing 53
  • 54. 8 reasons to use Kotlin 1 Null handling is a MUST! 54
  • 56. 8 reasons to use Kotlin 1 Null handling is a MUST! 2 Extension methods for improved auto completion 3 (Constructor) Properties 4 Lambdas done properly 5 (Local) Type inference 6 Named and default arguments 7 Compact syntax: No semicolon, new 8 Data classes replaces Lombok 56
  • 57. Kotlin is a great language . . . BUT! Data classes are still somehow restricted in their usage (v1.1) Paradigm shift of final-by-default clashes with existing libs Requires young padawan to be more disciplined Several classes in one (big) file gets common Explicit type declaration for documentation Overuse of single-expression functions Overuse of functionals like apply{} 57
  • 58. Apply – Who is this? 1 class MainPanel : JPanel () { 2 init { 3 val subPanel = JPanel () 4 subPanel.background = Color.RED 5 add(subPanel) 6 } 7 } We can refactor this to get rid of the variable reference. 58
  • 59. Apply – This is not this anymore! 1 class MainPanel : JPanel () { 2 init { 3 JPanel (). apply { 4 background = Color.RED 5 add(this) 6 } 7 } 8 } IllegalArgumentException: adding container’s parent to itself The solution is to use: this@MainPanel.add(this) But what happens if there are two nested JPanels?! PS: Kotlin 1.1 will come with a new function called also() 1 JPanel (). also { 2 this.add(it) 3 } 59
  • 60. 11 Kotlin 1.1 News 1 Compiler plugins (open-by-default, no-arg ctor) 2 Coroutines 3 Type aliases 4 Type inference for getters 5 Bound callable references 6 Local delegated properties & Inline properties 7 Inheritance for data classes 8 Subclasses of sealed classes in the same file 9 Destructuring in lambdas 10 Underscore for unused parameters 11 Underscore in numeric literals 60
  • 61. Links Visit Gadsu website: https://github.com/christophpickl/gadsu LATEX sources of slides: https://github.com/christophpickl/gadsu meetup Kotlin Vienna Meetup: https://www.meetup.com/Kotlin-Vienna Kotlin Slack Channel: https://kotlinlang.slack.com/messages/vienna/ 61
  • 62. One more thing . . . 62
  • 63. 63
  • 64. 64
  • 65. 65
  • 66. 66
  • 67. 67
  • 68. 68
  • 69. 69
  • 70. 70