Introducing MvRx: Android on Autopilot
At Airbnb, we are moving at a faster pace than ever. Each year, more and more people are using Airbnb to travel. This year alone, we have already launched Airbnb Plus and we have countless other…
Backup
It is Kotlin-first and Kotlin-only. Designing around the Kotlin language enabled us to build an API that is far cleaner than we ever could have achieved with Java

呢句真係好有感觸...

講真,冇 Kotlin 點樣可以寫到以下咁 Clean。
data class HelloWorldState(
  val title: String = "Hello World"
) : MvRxState

/**
 * Refer to the wiki for how to set up your base ViewModel.
 */
class HelloWorldViewModel(
  initialState: HelloWorldState
) : MyBaseMvRxViewModel<HelloWorldState>(
  initialState,
  debugMode = BuildConfig.DEBUG
) {
  fun getMoreExcited() = setState { copy(title = "$title!") }
}

class HelloWorldFragment : BaseFragment() {
  private val viewModel: HelloWorldViewModel by fragmentViewModel()

  override fun EpoxyController.buildModels() = withState(viewModel) { state ->
    header {
      title(state.title)
    }
    basicRow { 
      onClick { viewModel.getMoreExcited() }
    }
  }
}
Hello World in MvRx
而香港有一班未深入寫或設計 Kotlin Library 嘅人話「Java 都做到啦~」。可能佢地停留係 Kotlin 101 階段,連 Kotlin 比到啲乜野 Language Features 都未清楚就衝出黎 _ 。

學一種 Programming Language 最緊要先學習語言特性然後不斷開 Toy Project 練習使用;因為只有明白語言特性先可以有效地去 abstract 去 express 去創做一個 Software Architecture Pattern 改善生活。

呢一種學習模式只可能發生係 experienced programmer 身上,但有 Programming 經驗嘅人好多時以「邊做(Production) 邊學」模式去學習。

以 Java -> Kotlin 為例子,呢種學習模式,極多時候將其它本身設計去解決 Java 自身問題嘅 Software Design Pattern 帶到 Kotlin,阿 Gap 會用「Code in Java Way」去描述呢件事。但事實上 Kotlin 已經係語言設計上解決咗大量 Java 本身嘅設計缺陷,即係新加上去嘅 Software Design Pattern 解決緊無物,亦代表產生不必要的 Complexity。

唔係一下子寫到 Best Practices 真係唔緊要,真心嘅。

每個人都有學習階段,不知者不罪;但當有人好心話你知之後而你選擇拒絕 Refactor 就係一個問題。Java 無容置疑係其中一隻歷史悠久而且最少 breaking changes 嘅 Programming Language,由 Java 起手開始學習 condition, loop, recursive 等等概念並無不妥。

但要緊記每隻 Programming Language 都值得學習其特性。

Don’t code & design Kotlin in Java way.
Don’t code & design javascript in Java way.
Don’t code & design Swift in Java way.
Don’t code & design Scala in Java way.
Code & design any programming languages in its way.
airbnb/MvRx
MvRx: Android on Autopilot. Contribute to airbnb/MvRx development by creating an account on GitHub.