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

Kotlin Best Practices by Étienne Caron

GDG Montreal
February 28, 2018

Kotlin Best Practices by Étienne Caron

GDG Montreal

February 28, 2018

Transcript

45 slides
  1. Kaizen Approach : 1% Better Every Day https://goo.gl/C6VJcz “Compounding is

    the greatest mathematical discovery of all time.” — Albert Einstein
  2. Photo source info here Short Term • Books on the

    Basics • Best Practices and Idioms • Style Guides • Android Extensions + KTX
  3. safeLet(productIds, productVariantIds) { products, variants -> // Do some work

    } fun <T1 : Any, T2 : Any, R : Any> safeLet(p1: T1?, p2: T2?, block: (T1, T2) -> R?): R? { return if (p1 != null && p2 != null) block(p1, p2) else null } safeLet() Concisely Deal with Nullability
  4. Photo source info here TLDR; Use the code formatter. •

    No Tabs • No Wildcard Imports • Indentation 4 spaces • Line wrap at 100 chars
  5. Photo source info here Long Term • Architecture Patterns •

    Functional Programming • Reactive Programming
  6. Functional Programming Among other advantages, functional programming allows us to

    reduce side-effects, which in turn makes our code… • less error-prone, • easier to understand, • easier to test and • thread-safe. https://blog.philipphauer.de/idiomatic-kotlin-best-practices/
  7. Functional Programming In contrast to Java 8, Kotlin has way

    better support for functional programming: • Immutability: val for variables and properties, immutable data classes, copy() • Expressions: Single expression functions. if, when and try-catch are expressions. We can combine these control structures with other expressions concisely. • Function Types • Concise Lambda Expressions • Kotlin’s Collection API These features allow writing functional code in a safe, concise and expressive way. Consequently, we can create pure functions (functions without side-effects) more easily. https://blog.philipphauer.de/idiomatic-kotlin-best-practices/
  8. Photo source info here Books • Kotlin in Action •

    Kotlin for Android Developers • Android Development with Kotlin • Programming Kotlin • Reactive Programming in Kotlin • Mastering Android Development with Kotlin • Kotlin Blueprints • Kotlin Programming Cookbook
  9. Photo source info here Online Community •Android Kotlin Guides •Philipp

    Hauer's Idiomatic Kotlin Article •Kotlin Conf 2017 ◦ Huyen Tue Dao & Christina Lee's “Road to Kotlintown” ◦ Christina Lee's “Two Stones, One Bird”

More Decks by GDG Montreal

Other Decks in Technology