This 13 expert views on kotlin, and 80% of mobile developers have not heard

I really do not want to learn Kotlin it?

To answer this question, we first time dial back to May 18, 2017, the Android team at Google I / O 2017 conference announced Kotlin become the official language in first class support .

That time Google technology cattle Steve Yegge published an article on the use of experience Kotlin summary of the article: "Why Kotlin language better than the junk you used?"

For a time this explosive information in the hot-induced continues to this day.

Time is the sole criterion for testing truth, then we look at technical experts at home and abroad, using the experience kotlin development!

Google Android expert Annyce Davis: "When Kotlin appeared, I was immediately drawn to it because it reminds me a lot of grammatical properties of the Groovy both clean and refined.."

Google Android expert Sebastiano Poggi: "I really really like the language I personally think it makes coding in many cases become a pleasant thing, compared to before, will use the Java language coding under the same circumstances. I feel the pain and cumbersome .Kotlin sometimes makes me feel like a 10-fold developer productivity. "

Google Android expert Jorge Barroso: "Kotlin a big step in the development of Android, before that, the lack of properties Kotlin Android brings, compared to other Java platform, Java developers Android platform somewhat outdated, even now there in pushing Java 8, but it still will not become our favorite modern programming languages.

Google Android expert Mark Allison: "Although I also like Kotlin, but I do not think it's mature enough to be able to use online products lack maturity model and best practices, so that code written Kotlin may be difficult to maintain.."

Google Android expert Dmytro Danylyk: "For developers who remain in the world in terms of Android, Kotlin is a real game-changer, it has a lot of my favorite features: air safety type, data classes, attributes, and lazy loading, extended function, coroutine, stability and the like.

I loved using Koltin to encode, because I did not need to introduce too many third-party libraries in a project, Kotlin has been very good to provide most of the support. "

Google Android expert Anup Cowkur: "I have used such language like Haskell and Elixir is encoded, so when I Android development often wonder:" Why Android can not have such nice features? . "Now I use Kotlin, we can do."

David Vávra Google Android expert: "In my main application (Settle Up) production environment I use Kotlin, it is mature enough, but compared to Java (any version) has many advantages .Kotlin fully compatible with existing Java tools and libraries, and can be a good use in Android Studio in. If you now create a new APP, I would definitely choose Kotlin. "

After listening to a variety of Google Daniel boast, it is inevitable that Huangpojing his own trumpet suspect? Next we look at the domestic mobile development field the god of views on kotlin:

Hong Yang: "I will look at some of the new library or articles, including some outside Google's database every day, there have been very much a part of our external output by Kotlin, if I do not, I studied up to a certain hinder it. I chose to study Kotlin, in order to better learn! in short, we should understand their most immediate needs, rather than what technology the most popular. "

Guo Lin: "Before spraying kotlin, that with the construction of speed kotlin the project will be substantially reduced, and now I changed really fragrant!"

US Reviews round Enterprise Platform R & D Liuzi Peng: "I think the advantage compared to traditional Java Kotlin used in Android development, a lot of that depends on Kotlin syntactic sugar as well as more simple and easy expression syntax style can greatly improve development efficiency, reduce the amount of code, reduce maintenance costs.

For now the biggest disadvantage is the low penetration rate of the bar! Team development, if you are a person with Kotlin, it will certainly have some communication problems or conflicts. "

Ali droplets technical team: "If you had to develop business with Kotlin, soon realize that it is compared to the Java syntax is more concise and efficient such as Kotlin made these improvements:

To a large extent to achieve a type inference, and Java support only the derivation of local variables in SE 10.
Abandoned the static keyword, but the introduction of the object, you can directly use it to declare a singleton. As a comparison, Java must rely on to build the so-called "singleton" in order to express the equivalent.
Introduces some not in Java "special class", such as Data Classes (data type), Sealed Classes (sealed type), we can construct algebraic data types on a deeper level, the expression when used in combination. "

Tencent Bugly: "Why do we need to Kotlin? A: disappearing Getter and Setter, see also null pointer, Smart Cast, hit the log, goodbye Utils, good night ButterKnife ..."

After listening to the feelings of the above-mentioned experts use kotlin, then we re-analyze reason why you should learn Kotlin language completely from the technical level:

0 # Java interoperability

Kotlin is 100% interoperable with Java. You can continue to use Kotlin you always Java project development. All of you are familiar with Java frameworks are still available, any framework, whether Kotlin write, you stubborn or Java applets can be written partner.

# 1 familiar syntax

Kotlin not born in academia weird language. The syntax is any OOP developers are familiar with the field, you can more or less have some understanding. Of course, there are some different and Java, for example, reconstructed constructor and the val variable declarations, and so on. The following is a basic example code Kotlin:

2 # string interpolation

This is equivalent to a smarter, Kotlin more with readability of Java String.format () method implementation:

# 3 type inference

# 4 intelligent type conversion

Kotlin 编译器会跟踪你的逻辑代码并在需要的时候进行自动的类型转换,这意味着我们不需要在显示转换时做更多的 instanceof 检查:

5# 更直观的相等性比较

你不再需要调用 equals(),因为 == 操作符也可以用来比较结构的相等性:

6# 默认参数值

不需要像 Java 那样定义很多包含不同参数的相似方法:

7# 命名参数

结合默认参数值,命名参数可以消除 builders 的使用:

8# When 表达式

9# Properties

可以给公共字段自定义 set 和 get 行为,这意味着不再会因为那些没用的 getters & setters 导致代码疯狂膨胀。

10# Data 类

这是一个 POJO 类,包含 toString(), equals(), hashCode(), 和 copy()方法,和 Java 不同的是,它不会超过 100 行代码:

11# 操作符重载

可以重载预定义的一组操作符来提升代码的可读性:

12# 解构声明

一些对象是可以解构的,一个很有用的例子就是对 Map 进行迭代:

13# Ranges

14# 扩展函数

还记得你第一次用 Java 实现一个 List 的排序吗?你找不到一个 sort() 函数,然后你就四处求助,最终找到了Collections.sort()。后来你需要将一个字符串的首字符变成大写,最终你还是自己写了一个方法来实现,因为你当时还不知道有这么个东西StringUtils.capitalize().

如果只有一种方法可以向已有的类添加新的函数,这样 IDE 就可以帮助你在代码完成时找到正确的函数。在 Kotlin 里你可以这么做:

Java 是我们应该称之为是一个几乎静态类型的编程语言。Java 的 String 变量类型无法保证它不会等于 null。尽管我们已经习惯了这样的情况,但它否定了静态类型检查的安全性,导致 Java 程序员总是活在各种空指针异常的恐惧中。

Kotlin 通过区分非空类型和允许为空类型来解决这个问题。类型默认是不允许为空的,可以通过在后面加一个 ? 问号来表示允许为空,例如:

Kotlin 强制你必须在访问一个可为空的类型变量时候必须确保不会发生空指针:

虽然看起来有点麻烦,但这的确是 Kotlin 一个微小却又非常重要的特性。我们仍可以使用智能的转换,可以在需要的时候将允许为空的类型转成不允许为空:

我们也可以使用安全调用方法?. 该表达式在 b 为空时返回 null,而不是抛出空指针异常:

安全调用可以链接在一起,以避免像其他语言一样存在大量嵌套的 if-not-null 检查,如果我们想要一个默认值而不是 null 时,可以用 ?: 操作符:

如果没有适合你的,那么你应该是需要一个空指针了,你将不得不显式的进行处理:

16# 更好的 Lambdas

嘿,帅哥,这是一个很好的 Lambda 系统 —— 在完美的可读性和简洁之间取得非常好的平衡,这得益于非常聪明的设计选择。其语法简单直接:

优点体现在:

  1. 如果 lambda 是方法的最后一个参数或者是唯一参数的话,那么方法的括号可以移动或者省略.
  2. 如果我们选择不去声明单参数的 lambda 表达式的参数,那么 Kotlin 会隐式的将之命名为 it.

结合上述优点,下面的三个不同的语句效果一样:

这个可以让你编写更加简洁的函数式代码,就像下面这样优雅:

Kotlin 的 lambda 系统和扩展函数结合,可以非常棒的用来开发各种 DSL。例如 Anko 这个 DSL 的例子可以增强 Android 的开发:

17# IDE 支持

如果你打算开始使用 Kotlin 开发项目,在工具上你会有很多的选择。但我强烈推荐使用 IntelliJ ,因为它自带 Kotlin 的支持 — 它的特点展示了同一组人设计的开发工具和语言时的优势。

如何学习kotlin?

需要我们去学习官网教程 或者 google 提供的快速学习的教程,当然这里只是快速浏览就行了,主要还是得靠实践,先熟悉基本的语法,然后找时间对语法进行了解,最后在实践开发中使用高阶特性。

官网教程-中文:https://www.kotlincn.net/docs/reference/
kotlin项目实战专题资料
需要上述kotlin项目实战专题资料的朋友,添加VX:13203163609,即可免费领取

Android_Alvin_

Guess you like

Origin www.cnblogs.com/Android-Alvin/p/12409010.html