Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Transformation from Java-Kotlin to Kotlin Style...

Transformation from Java-Kotlin to Kotlin Style Programming

This is a talk in Kotlin Everywhere in Boston conducted on the 8th and 9th of November 2019
In this talk I walk thru the basics of the baggage that a developer with experience in Kotlin carries and how it can be reduced when writing the code in Kotlin.

Link to the talk
https://www.youtube.com/watch?v=SMa8EaYlGrU&list=PLHNdTenpo3pieslLcqGfqBV4a6pXFOZCC&index=23&t=0s

Avatar for Nithin Putchakayala

Nithin Putchakayala

November 08, 2019

Other Decks in Technology

Transcript

  1. Kotlin • Unveiled by Jetbrains in 2011, 1.0 was released

    in 2016 • Given first class support in 2017 by Google • Android made Kotlin-first in 2019 by Google 3 @nithinpvnk
  2. “ This code block looks like a case of writing

    Java code in Kotlin.” 7 @nithinpvnk
  3. Java Kotlin 9 • Synthetic attributes • Safe call •

    Built-in extensions • Lambdas @nithinpvnk
  4. But how to? • Data classes • Sealed classes •

    Null Safety • Built-in extensions 10 @nithinpvnk
  5. Java-Kotlin Kotlin 13 @nithinpvnk • All the parameters need to

    be either val or var • Cannot be abstract, open inner or sealed • Can implement interfaces or sealed classes
  6. • Classes used for restricted hierarchies • Feature which is

    kind of a hack in Java Sealed Classes @nithinpvnk 14
  7. Built-in Extension Functions let with run also emptylist apply take

    Unless takeIf decapitalize replaceAfter endsWith format zipWithNext singleOrNull capitalize replace retainAll maxBy remove associateBy times minBy elementAtOrNull minus filterNot takeLast fold plus windowed reduce shuffle zip filterNotNull contains firstOrNull filterTo swap asReversed map mutableListOf mapIndexedNotNull flatten flatMap groupBy slice take dropWhile chunked sortedDescending reversed union binarySearch drop takeWhile fill takeWhileLast 22 @nithinpvnk
  8. 24 Let @nithinpvnk • Has context object available as an

    argument called by default as “it” • Used to introduce local variables with a limited scope for readability • Invoke nested calls to functions
  9. 26 @nithinpvnk • Run(Object reference “this”) is similar to Let(Object

    reference “it”) • Also(Object reference “it”) is similar to Apply(Object reference “this”)
  10. 27 @nithinpvnk • Let (Object reference “it”) : Executing lambda

    on non-null objects Introducing variable in local scope • Run (Object reference “this”) : Object configuration with computation of result • Apply(Object reference “this”) : Object Configuration • Also(Object reference “it”) : Additional effects
  11. • Make use of Data and Sealed classes • Understand

    and respect nullability • Utilize built-in extension functions • Learn and update on the feature set available 30 @nithinpvnk
  12. Thank you 32 @nithinpvnk Twitter and IG - @nithinpvnk Linkedin

    - https://www.linkedin.com/in/venkatankp