Kotlin as Your Next Language, a speech given by Co-founder Peter Guo at the 2017 Google Developer Festival in Beijing, China, was posted online on November 19, 2017. IT big said as the exclusive video partner, by the organizers and speakers review authorized release.

Read the word count: 1700 | 4 minutes to read

For video and PPT, please click t.cn/EZrTPAl.

Abstract

This time, I will share with you our company’s analysis of several mainstream languages, in-depth analysis and discussion from several dimensions of programming style, community ecosystem, tool chain and type check, and finally decide to include Kotlin as a new server-side language technology stack of the company. This post will give you an overview of some of the features and styles of the major languages that will inspire developers interested in programming languages but still hesitant to use them.

Language selection

In 2017, due to the rapid development of the company, our technical reserves could not keep up with the requirements of the business, so we had to consider the issue of personnel recruitment. And in order to more quickly attract the right talent, a variety of technology stack research.

Currently we use JavaScript& TypeScript on the front end, Ruby on the back end with a small amount of Node.js, and Golang on the operation side.

The back end was the main bottleneck in terms of recruitment, and at that time we were working on microservitization, so we wanted to add a technology stack on the back end to facilitate recruitment.

To find the right language, we looked at IEEE and StackOverflow’s list of popular languages in 2017 and divided them into different dimensions for analysis.

It is important to note that the following analysis of these languages is 30% objective fact and 70% based on our own views of these technologies based on Web application level and personal preference for programming style.

Microsoftor Non-Microsoft

Belonging to Microsoft means using.net, which requires using Windows servers and paying Microsoft an annual fee. Although.net can run on Linux at the moment, most of it will run on Windows servers, which is not easy for startups like us to use.

Of the two lists mentioned above, only C# and TypeScript belong to Microsoft. Unlike C#, TypeScript is still considered because it compiles to JavaScript and is not dependent on Microsoft’s environment.

StaticTyping or Dynamic Typing

The second dimension is static and dynamic typing. Let’s start by looking at the advantages of each language.

Statically typed languages have good support on the IDE, such as auto-completion; Performance is also better, the compiler can do some low-level optimization; It is also friendly to beginners, for example, there is no need to guess the parameter types of functions or methods; You can also use analysis tools to solve problems at compile time.

While dynamic language writing efficiency is faster, more simple, no compilation process, can be faster iteration.

In general, static languages are more suitable for large projects.

This is what happens after categorization. It’s interesting that Typescript and Elixir are separate because they both fall under opt-in Typing.

This type has the advantages of both dynamic and static languages, and developers can decide when to add type restrictions based on the situation.

Despite this advantage, many third-party libraries need to be used in actual program development, and some third-party libraries do not have some features of opt-in Typing, resulting in fragmentation. Microsoft has done a better job of this, spending a lot of money working with third-party library developers to add typescript features that were missing.

TypeInference

We all know that static languages are cumbersome to write. Typically, variable types need to be declared in advance. However, if we have a deeper understanding, we will find a feature of some static languages that can solve such problems well, which is Type Inference — Type Inference.

Let’s take a look at an example. Above is the Java and Kotlin code, respectively. We can see that the Java variable needs to be declared as a String, while Kotlin does not need to declare this process.

There are two types of languages with type derivation, Global and Local. Global’s languages are Rust, OCaml, Haskell, while Local’s languages are Scala, Typescript, Golang, Kotlin.

ProgrammingParadigm

At present, there are three main programming styles. One is Imperative, a typical representative of C language, which directly tells the program how to run. There is also Object OrientedProgramming (OOP) that most people are familiar with. It is based on the abstraction of real things. Java is the object-oriented type of language.

The other is Functional Programming (FP) Functional Programming, which differs from Imperative in that it pays more attention to the logical relationship between programs. Such languages, such as Lisp, Haskell, etc., usually have first classes and higher-order functions.

The figure above is an analysis of the selected language. The closer the language is to a certain direction, the stronger the feature is. It should be noted that the stronger the feature in one direction does not mean the absence of the other two features. Generally speaking, the more oriented object-orientend (OOP) or Imperative is, the easier it is to learn. This is because these two modes are more similar to normal thinking of human beings, while Functional (FP) is more like the thinking mode of mathematicians.

However, for our own sake, we still need some FP-specific languages, as shown on the right.

Ecosystem

Based on our initial consideration, Ecosystem is very important. There are considerations such as the number of developers, whether the toolchain is easy to use and rich, how well the IDE is supported, whether third-party libraries are sufficient, and so on.

At present, the relatively large ecosystem includes JavaScript, JVM and GO. The biggest, of course, is the JVM.

conclusion

Through the above layers of analysis, we finally chose Kotlin. It’s not a Microsoft language, it’s a static language, it can do type inference, it has OOP features and Functional (FP), and it relies on the largest JVM ecosystem to date.

Of course, this is only for the current stage, I believe that with the development of time there will be a better choice.

That’s all for today’s sharing, thank you!