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

Kotlin - Padrões e Boas Práticas

Kotlin - Padrões e Boas Práticas

Apresentada no DevFest Belo Horizonte 2017

Avatar for Rafael Toledo

Rafael Toledo

November 18, 2017
Tweet

More Decks by Rafael Toledo

Other Decks in Programming

Transcript

  1. class User(val name: String, val email: String, val phone: String?

    = null) User(name = "Rafael Toledo", email = "[email protected]", phone = "+55 11 99999-9999")
  2. taxCalculator { country = Tax.COUNTRY_BRAZIL period { from = date("2017-01-01")

    to = date("2017-10-31") } type = Tax.TYPE_IRPF payment { type = Tax.PAYMENT_BANK_TRANSFER bank { agency = "1234" account = "012345-9" ...
  3. fun ViewGroup.inflate(layoutRes: Int, attachToRoot: Boolean = false): View { return

    LayoutInflater.from(context).inflate(layoutRes, this, attachToRoot) }
  4. // Confuso if (value?.isTrue ?: false) { ... } //

    Parece redundante, mas é mais claro! if (value?.isTrue == true) { ... }
  5. // Em vez de apply plugin: "kotlin-android" apply plugin: "kotlin-android-extensions"

    // Por que não... apply plugin: "org.jetbrains.kotlin.android" apply plugin: "org.jetbrains.kotlin.android.extensions" apply plugin: "org.jetbrains.kotlin.kapt"