Share
Embed
Transcript
26 slides
-
HELLO! I am Abangkis Pribadi I am 2 months android
developer. You can find me at @abangkis 2 -
About Kotlin ▸ Kotlin is a statically typed programming language
that runs on the Java virtual machine ▸ Can also be compiled to other language such as javascript, android & native ▸ Publicly Unveiled July 2011 after 1 year of development ▸ Relaxes Java’s restrictions, allow functional programming style -
Great things about kotlin ▸ Concise Drastically reduce the amount
of boilerplate code ▸ Safe Avoid entire classes of errors such as null pointer exceptions ▸ Interoperable Leverage existing libraries for the JVM and the browser. Can work with existing java code in Android ▸ Introduce new approach Coroutines, Ktor architecture -
Things to consider when migrating ▸ The language itself ▸
The ecosystem (library, framework, doc, googleable/stackoverflow) ▸ Your team ▸ Your code, your utility class & lib ▸ How long do we need to be back to the same productivity, and more! (how long must we take a hit on productivity) -
Why Now? - Timeline ▸ July 2011 - Publicly Unveiled
(after 1 year of development) ▸ February 15, 2016 - Kotlin v1.0 was released ▸ Google I/O 2017 - Google announced first-class support for Kotlin on Android (wizzard, kotlinx.android.synthetic, gradle, etc) ▸ September 14, 2018 - Koin 1.0.0 unleashed ▸ October 29, 2018 - Kotlin coroutine 1.0 released ▸ November 19, 2018 - Ktor 1.0 released -
Why Now? - Development Speed ▸ Less code ▹ kotlinx.android.synthetics
▹ Set listener / anonymous class ▹ Data class ▹ At least 20% less code vs Java ▸ Tools ▹ More tools are built for kotlin ▹ Popular library now support kotlin ▸ New Arsenal ▹ Kotlin coroutine -
Learning new stuff - the long way ▸ Concept ▸
Syntax ▸ Gotchas ▸ Common & Best practices -
“ Prag·mat·ic /praɡˈmadik/ Adjective dealing with things sensibly and realistically
in a way that is based on practical rather than theoretical considerations. -
Learning new stuff - pragmatic way ▸ Concept - Minimum
▸ Syntax - Minimum ▸ Gotchas - Immediate ▸ Common & Best practices - Immediate The goals is to learn the essential to make it work. Supplement it with our experience. While adding new knowledge over time. -
Beware ▸ Leveraging old knowledge ▹ Java & Best practice
knowledge ▹ Android dev knowledge ▹ Written blog ▹ Reads articles about kotlin -
Start from Zero ▸ The things that we know ▹
Interoperability with java ▹ Can be used parallel with java in android project ▹ Have simpler syntax ▹ Can mix between OOP and Functional Programming ▹ Design specially to handle null safety ▸ IDE Support ▹ Java to Kotlin converter ▹ Kotlin bytecode decompiler -
Basic ▸ val vs var ▹ var is mutable variable.
You can change the variable later on ▹ val is immutable variable. You can’t change the variable but you can still manipulate the content ▸ Null Safety ▹ Kotlin's type system is aimed at eliminating the danger of null references from code ▹ Type system distinguishes between references that can hold null (nullable references) and those that can not (non-null references) ▹ The goals is to make your code cleaner and safe from Null cases -
New Syntax ▸ If you’re used to java, need time
to accustomed to this type of syntax (even some of you would protest a lot) ▹ Reverse notation ▹ Infer type ▹ The curly braces (Scope) ▹ Etc ▸ Take it slowly, you’ll get used to it -
The Functional Side ▸ In Kotlin function is the first
class citizen. ▹ That means that they can be stored in variables and data structures, passed as arguments to and returned from other higher-order functions. You can operate with functions in any way that is possible for other non-function values. ▸ That means we work a lot with anonymous function/ Lambda expression ▹ Lambda expressions are 'function literals', i.e. functions that are not declared, but passed immediately as an expression val sum = { x: Int, y: Int -> x + y } -
Evolve your code ▸ Android Synthetics ▸ OnClickListener ▸ Recyclerview
▹ Create Kotlin Adapter ▹ Convert Item to kotlin item data class ▹ Populate with mutable list of ▹ Simplify the adapter ▹ Add on item click -
Infrastructure ▸ Architecture component ▹ Lifecycle-aware components ▹ LiveData ▹
ViewModel ▹ Room ▸ Dependency Injection ▸ Repository Pattern ▸ Retrofit -
Using Koin ▸ Create the repository ▸ Create the module
▸ Extend the application, startKoin ▸ Create view model ▸ Access it from activity -
Room Database ▸ Entities, Dao’s works the same ▸ Even
simpler with kotlin format and Koin Injection ▸ All we have to do is to wire it up to koin -
THANKS! Any questions? You can find me at @abangkis &
medium.com/@abangkis Source available at https://github.com/abangkis/IntoKotlin/ 25 -
CREDITS Special thanks to all the people who made and
released these awesome resources for free: ▸ Presentation template by SlidesCarnival ▸ Photographs by Death to the Stock Photo (license) 26