This talk elaborates our awesome journey migrate all our micro services from Java to Kotlin. We will take a closer look at the challenges we faced as a team and the impact on our day to day work in an agile environment and how we overcame technical hurdles integrating with Spring Boot and introducing async workflows using Kotlin coroutines. Finally we discuss at the actual benefits that we gained by moving all our micro services to Kotlin and do a critical review of our journey and an outlook at things to come.
7. Checked exceptions
7
public static void refundExcessMoney() throws ExternalPspFailureException {
// try to refund money
throw new ExternalPspFailureException();
}
try {
refundExcessMoney()
} catch (ExternalPspFailureException e) {
// log or rethrow
}
8. Single abstract method types
8
public interface Comparator<T> {
public boolean compare(T a, T b);
}
public class PaymentComparator implements Comparator<PaymentInformation> {
@Overwrite
public boolean compare(PaymentInformation a, PaymentInformation b) {
...
}
}
22. Switching to Kotlin frameworks
22
KTOR - asynchronous Kotlin web framework
Spring Boot - established Java web framework
Often less matured
Often less documented
No need to forcefully use
Kotlin libraries and frameworks
24. Review
24
Challenge which we mastered as team
Migrating was worth the effort
Improved design and new focus on language
Quality of life update
10/10 would use Kotlin again
25. A heads up
25
Test coverage is a must have
Consider your people and eco system
Consider language and framework maturity level
Amount of new things can be overwhelming
26. Outlook
26
Establish Kotlin at METRONOM
Help others introduce Kotlin
Introduce more native Kotlin frameworks
Find new passionate developers
27. Follow us on Twitter and Instagram
@bjoernwendland
@joinmetronomnow
#METRONOMians #wearedevs19 #passion #ambition #purpose
Hall A
Booth A11
About Metronom
‚The biggest software company you never heard about‘
METRO’s tech unit providing solutions to customers and employees
'Setting the pace in food an technology‘
About Metro
German global diversified retail and wholesale/cash and carry group based in Düsseldorf
About me
Joined METRONOM last july as Full Stack Developer
Became Kotlin Ambassador at METRONOM over the cause of the last year
Reasoning behind migrating to Kotlin
How to approach the task
What we’ve learned in the process
Why did we choose Kotlin?
A developers curiosity
Java 2.0
It is close enough to the previous eco system (JVM / Spring Boot/ PostgresDB)
Justification: “Setting the pace in food and technology”
About the design
Started with Java microservices based on proprietary (yet open source) web framework
Unhappy with Java’s design
Feeling of being outdated and heavy
Finally tipping the scale
Google announcing Kotlin as officially supported for Android
Level of maturity
By now Kotlin became the suggested language for Android development
Checked exceptions
Single Abstract Method Types (SAM Types)
Wildcard Types
Benefit: compiler error if exception is not handled
Disadvantage: laborious and results in harder to read code
Kotlin has unchecked exceptions
Lambda expressions are considered a SAM type and can be freely converted
SAM Type not bad in general, but propper function types are prefered
Kotlin has proper function types opposed to SAM-conversions
Not explicit / lacking information
Unsafe (needs casting)
Can be confusing
Kotlin has use-site variance without wildcards
Null-safety support in Kotlin typing system
Extension functions
Smart casts
Coroutines
ATTENTION: Java libraries null-safety can not be infered
ATTENTION: How to manage extension functions?
Using Coroutines
See how async code is composed in real world code
runBlocking launches coroutine
withTimeout keeps runtime in check and throws exception of needed
Read new event
Delay:programmer allowes code to be scheduled at this point
Infinite loop
And return value
Still reads like sync code, but allowes to be yielded
It handles waiting for a response very greaceful
Safe against infinite loops
Why did we choose Kotlin?
A developers curiosity
Java 2.0
It is close enough to the previous eco system (JVM / Spring Boot/ PostgresDB)
Justification: “Setting the pace in food and technology”
About the design
Started with Java microservices based on proprietary (yet open source) web framework
Unhappy with Java’s design
Feeling of being outdated and heavy
Finally tipping the scale
Google announcing Kotlin as officially supported for Android
Level of maturity
By now Kotlin became the suggested language for Android development
Structured process
Intellij’s automatic code conversion for class
Fix non compiling code / non translatable language constructs
Refactor, even partially rewrite methods
Verify correctness using unit tests
Convert unit tests
Migrate to Kotlin libraries
Goal was a 100% Kotlin micro service
Mockk, Asskertk, Klaxon, etc.
Add a library / framework next to existing one
Phase out previously used Java framework
Goal was a 100% Kotlin micro service
Spiked KTOR and Spring Boot
We decided to use Spring Boot, because it is fully documented and it enforces the project structure
KTOR not yet mature enough and lacks documentation also does not enforce a project structure
Will be considered again, since it is more lightweight and has better performance
Finally a look back
And one ahead
Disclaimer
Does not only plly to Kotlin
If anyone is looking for a new job and wants to work with Kotlin
Structured process
Intellij’s automatic code conversion for class
Fix non compiling code / non translatable language constructs
Refactor, even partially rewrite methods
Verify correctness using unit tests
Convert unit tests