Part 3 : Picking Kotlin for Android — Swift in Android?
Kotlin is maturer, unlike Swift 1.x/2.x
I have seen a lot of iOS developers who has tried Kotlin with their first glaze and most of them would very likely to use the following statement to describe Kotlin:
“Kotlin in Android” is just like “Swift in iOS”
But, from my personal experience on Android & iOS development. I think “Kotlin in Android” is MUCH BETTER and MATURER than “Swift in iOS” .
If you have experience on coding Swift in iOS by using Xcode, you should have experienced some really really bad. And I would like share my list of complaints :
- Too many breaking changes on Swift standard API (from Swift 1.0 to 3.0) — Let’s wait to see the breaking changes on Swift 4 :p .
- Xcode* keep crashing — boom ! “Xcode quit unexpectedly”.
- Xcode* keep showing “internal error” — boom! All syntax-highlight has gone and you can only wait for the Xcode self-recover by making some line changes.
- Xcode* has NO “Refactor” features for Swift
- Swift Compiler is too weak to work on “Type inference” — Result in Long compile time. When the expression is too complex and it fails to find the correct Type, compiler will ask you to type it manually. Sometimes, seriously, the compiler will encounter “segmentation fault” because of Type inference.
- Xcode’s* Swift inspection is very slow — The best approach is never wait the Xcode to prompt syntax error, after writing a lot of code and directly press ⌘+B to compile and wait the compiler prompt any syntax error you had made.
- Swift SourceKit inspection is not accurate — For example, missing a
}
of a closture would result in unrelated error messageXXX is not convertible to YYY
. It is really annoying and confusing, especially for new comers. - Swift SourceKit inspection is disruptive — Every time when I had made a typo mistake on syntax. i.e. missing a
{
or}
, Xcode mark the line with red and STOP doing syntax highlight on the later code or even crash on “internal error”. It really annoys my normal work flow. I solve this problem by using Intellij App Code which I feel more productive and zero-annoyance when coding some non-UI logics. - Objective-C syntax is too strange to Swift-Only developer — Many useful third-party libraries still using Objective-C but Swift has grow very fast and I believe “Pure Swift iOS Project” will solve this problem.
*Experienced with Xcode ≥ 7.0 && ≤ 8.1, iMac 27"(Retina) 2014 Late i7 32GB Ram
Kotlin with the Best IDE
All of the aforementioned bad parts of “Swift in iOS” are NOT valid to “Kotlin@Android Studio”. JetBrain has provided a very good IDE support for Kotlin.
Android Studio (≥ 2.0) with Kotlin:
- Super smooth & stable, nearly NO crash
- Inspection and auto-complete is fast
- Concise and accurate syntax error message
- Compiler is clever enough to work on complex type-inference(i.e. Nested Lambda)
- Trustworthy Refactoring
- Work with Instant Run