Why do you recommend using Kotlin language?

Source: Internet
Author: User

Google Daniel said: Why Kotlin than you use the rubbish language is good

Original title: Google Daniel said: Why Kotlin than you use the rubbish language is good

Compilation: Bole Online/Huang

"Bole Online/Programmer's Things Guide": May 18, the Android team at the Google I/O 2017 conference announced that Kotlin became the official first-class support language. This explosive information on the day is Hacker News home hot discussion. On the same day, Google technology Daniel Steve Yegge also sent a summary of the use of Kotlin articles, the same is also popular on the homepage, and triggered 200+ discussion.

(Steve Yegge)

Why is it that Kotlin is better than all the junk language you use?

?? Ha, the topic of the title of the party let you click in to see it. Don't be surprised, now the title party is popular online. And the answer given in this article is sure to shock you.

Honestly, I don't want to attack your language beliefs ... At least not a "big" thought. After all, the time when your favorite language is going to shine may go back to the Ice age, right? If the language you like is not dead today, it can only show that the language is gradually improved and updated to keep pace with the times.

But what about the speed of improvement? All right...... Assuming you're using a language that happens to be Java, and you're addicted to the idea that Java used to be a very good language, you're screwed. And it's already finished. Even though humans are less inclined to think about the ultimate fate, Java 8 is simply a replacement for some of the language features compared to more than 20 years ago, and you can't help thinking: "Do I really have to spend the rest of my life with this language?" Or is Java the only way to do that? ”

Because I finally started to do Android development, I put all kinds of old language problems once again. I have written an old game Wyvern, this game already has an IOS version, recently I decided to engage in another Android version. I never expected that computer language would make me "Think about life" (for example, "Am I a son of a man wasting my life?"). If you've ever written an Android app, you know that in the Android world, the language problem is going to be pretty tough for you.

The first time I tried to write an Android app was last summer, my God, that felt like crap. Actually, someone warned me. They all say, "Those APIs are hard to do." "And I don't listen." Bent.

I think: where can these things go bad? Isn't that Java anyway?

Historical code of the disaster

It's really bad luck--because of complicated historical reasons and no one cares--the core API of Android is really awful. I mean: It's really bad, it's really bad, it's really bad. You can only turn off reference books, take a deep breath, and then go out and drink coffee to crush yajing. The warnings that people gave me before seem to be perfectly correct.

The Android API Library is a treasure chest. Many APIs are really good to use. I can say that many of the things that are very hard to do in IOS development are easy on Android. Product Flavors, Downloads Services, Findviewbyid () methods, Preferences activity, and so on, are all good examples. There are too many things in Android that are in iOS, so you can always see in iOS that the developer's own disgusting and elegant application library coexists.

but ! Note that the left is an uppercase bold but! When writing an Android app, people focus only on the bad APIs, just as you can only get a few red lights on the road when you're driving, and the number of green lights is no one's concern. Because people will only pass the number of red light to evaluate whether the road is fluent.

Android does have a few very bad "red" APIs. For example fragments, this is the sign API in the Andoird "red light" API. The entire life cycle of this API has been horrendous, well, activities and fragments. In other words, IOS does not have such a bad API. I tried these APIs last summer and they were so bad that I gave up. I was completely served. Go to it, I will find someone to help me write these procedures later.

In the next 1.5, I didn't touch Android programming.

The Savior from Russia

I have always heard that there is a new language called Kotlin, which can be used to write based on the JVM or Android program. It is not the other countries that invented this language, it is the fighting nation Russia. More specifically, it was developed by JetBrains. JetBrains is the world-renowned IDE developer, Intellij idea, and their lovely and famous orange, green, purple and black mixed Dark "darcula" theme.

Figure: An old age demon can't restrain the excitement of Java 8

So why give this language the name Kotlin? Well, one of the arguments is that Java's first letter is "J", while Kotlin begins with the next letter "K" in Java. In addition, it is suspected that (this conjecture may come from the University of California, Berkeley), "Kotlin" the name of the inspiration also comes from the "Kremlin", "Khrushchev" and "KGB". These were the pride of the former Soviet Union, so they used the name "Kotlin", a former Soviet military base, to name the language. Anyway, that's a good name, and you'll get used to it.

Bole Online Supplement: Steve Yegge in the previous article about Kotlin's name source, should be wrong. In his own original comments, there are also netizens pointed out.

The right thing to do is: ①jetbrains is a registered company in Prague, Czech Republic, with a total of 6 offices worldwide: Prague, St. Petersburg, Moscow, Boston, Munich and Novosibirsk. But the main management and developers are in St. Petersburg. The island of ② in the Gulf of Finland is "kotlin/Catalina", 32 kilometres west of St. Petersburg.

I found last year the industry about Kotlin just a lot of "buzz". Note that it's just "muttering", not bragging about hype. People are just "muttering" about it in low-key. Well, anyway, I looked at it and I thought it was the same language as the 50 to 100 computer languages I've seen in the last 15 years, and it's an alternative to Java, and of course, I think any rational language can replace Java.

The first impression of Kotlin

The first time I saw Kotlin, I really felt that this language could not be used in real life, really is not a possibility. In fact, I also just skim through. My first impression? There is no big problem with the language. It is concise and has advanced features. If it's fashionable, it's almost all about the latest trends in computer language design. But it's not a big deal, because many languages also meet this point. For example, Rust. Rust is also a strong, well-named language, but no one uses it.

Kotlin gave me a strange feeling is "déjà vu", later I reacted, originally this is because it and Swift very much like. I didn't respond immediately because my IOS program had to be written in objective-c rather than Swift because of the history code. And now I understand: In fact, Kotlin's history is a long way from Swift, so the right thing to say is that swift and Kotlin are alike.

But even then I wasn't ready to work in that language. Kotlin is a very grammatical and elegant language for me, but I don't think I have enough of this language to be able to use it to cope with the brutal realities of the work.

Defected from Java to Kotlin

I don't quite remember how I was specifically in love with Kotlin. But I'm sure it's definitely not intentional.

I tried to recall, the thing is this, I do the game of the players told me for a long time, let me develop an Android version. The game was on the Apple Store in December, and in a few weeks, a lot of fans told me that they were andorid users, so they couldn't play the game. So, even though I had "sworn" to Never touch Android again, the user was God, so I started trying again. But this time it will be a different way-no more appetite in the Android Java language. I need a ready-made framework, or something like that, to make the job a little bit easier.

In mid-January, I made a rough assessment and then decided to use Kotlin to develop it, and Kotlin was able to support both Dalvik and ART two Android virtual machines at that time. I think my assessment is based on the following reasons:

    • 1. Kotlin has a small reputation;

    • 2. I wanted to use Swift when I wrote the IOS version (but it didn't work);

    • 3. Kotlin has a pretty good Android DSL called Anko, which reminds me of my interest, although in the end I didn't really use it.

So I started doing it with Kotlin. Over the next 4-5 weeks, I rewrote the game's service platform with Kotlin. It's more than 20 years old before you know the platform. After one months of Kotlin, I was completely conquered. I'm not talking about Scala or any other language, but Koltin is perfect for me as a common-code farmer. My request is not high, give mouth rice to eat on the line, know? Scala is good, but it's too good to be true, like a bullfrog's brain truffle snail. To know that I am a blue collar, Clojure, Scala language is too big for me.

It took me about 3 days to learn the grammar of Kotlin, and then I began to formally program it, although I was still very unskilled, but I knew that the language and IDE tools were enough for me to solve all kinds of problems.

When I was a little acquainted with the language, I knew that I should not fall in love with another language, because Kotlin was so fascinating. What you write in the code makes you feel cool. Of course, I have experienced similar feelings when programming in other languages, but the learning curve of those languages is generally very steep . Kotlin, it's the Savior: Kotlin appears when Java programmers are scratching their heads over a bunch of new concepts from Java 8. Kotlin can implement a variety of new features in Java 8, and through the support of coroutines, can actually achieve more powerful functions, but also more concise grammatical expression. Java 8 can actually express interesting logic, but it's tedious, and it feels like you're going to have to put sand in your mouth before you talk.

The reason I think Kotlin is easy to get started is too obvious, thanks to its IDE support. Now almost all of the JVM languages or IDE support for the Android language are maintained by several volunteers in the community (except Java, of course). Kotlin is a world-class IDE manufacturer (JetBrains), so Kotlin started with IDE support. How many languages do you have to have IDE support from the beginning of the invention? The evolutionary process of programming languages is generally not a thing to do. Besides, some programming languages have to avoid the IDE from the beginning (hi! ROB) Another language that can be supported by the IDE is C #, but C # is undoubtedly one of the best programming languages in the world.

Bó Lè Online/Programmer's Things to note: Rob Pike, the inventor of the go language, should be referring to the author of the went languages, where the writer may be the irony of the go language from invention to now there is no reliable IDE support it.

As a language that comes with IDE support, when you hit code in Kotlin buffer, typing is basically right. The IDE will help you complete all the parts you haven't finished. You know, you can even copy the Java code into the IDE, and the IDE will automatically convert it to Kotlin code. If you think Java IDE is good, then I can be honored to tell you, Kotlin IDE will this "good" advance to the point of unprecedented. Even a former Microsoft engineer told me: "I thought Microsoft's Visual Studio was the benchmark for the IDE, and it couldn't be surpassed." But I think IntelliJ idea does have to be better. "In my opinion, because I'm not familiar with Visual Studio, I'm just quoting what he said here. But I think IntelliJ idea is at least the same level as VS.

Admittedly, I still have to switch to Emacs often in real-world work. IntelliJ a little bit of a reaction when you're typing fast. If you type always only hit half, then the auto-complete kinetic energy of the operating pressure is still very large. Moreover, the processing of plain text is bad, which is a common problem for all Ides. So the IDE and Emacs are all you need to use. Unfortunately, Emcacs's support for Kotlin is now just as good, but I believe it will be getting better. I'm switching back and forth between Emacs and IntelliJ anyway. It's OK at the moment.

That's it. It took me about 10 years to find a language to replace Java. I really look hard and hard. Ironically, after I gave up, this stuff actually came out. Go check it out. Kudos is a stunning achievement for jetbrains.

Android:kotlin's killer.

The new programming language is hardly a big influence these days. It is not that there is no new language now, on the contrary, every year there is a good quality of the new language produced, but then eggs, no one use! It is difficult to delimit the "impossible" boundary. But the market for computer language is already very saturated. If a new language is to fire (and this rule has been in existence for the past 10-20 years), then the language must have a "killer" application. This language needs to be tied to a platform that makes it very urgent for everyone to use this platform, so that you can learn the language in order to program on this platform.

For now, the killer app we're talking about--that's what we've got on top of it--is Android's disgusting API. Every time you go down the Android route, you'll get stuck with the API, which will only give you a curse on the Android platform. Android no matter how many good API does not work, it is important that Android bad API too much, so you have to stop to find "ready" method (solution).

But brother, there are a lot of "ready-made" solutions to the problem in Android. For starters, there's a whole bunch of Java annotation processors available, which is a hint of the language problem. Not to mention a bunch of mini-frames (like Lyft's Scoop). There are frameworks that are completely independent of Android (Java): React Native, Cordova, Xamarin, flutter, and more.

If you do not like the above mentioned technology, then you can also solve the problem from the language point of view. Of course, those completely independent frameworks are language-specific, not java.

The competitive advantage of Kotlin is that it is not completely isolated from the Java language. It is basically 100% that can be translated into Java with each other. This is much like C + +, but they do not have 100%. Kotlin is also evolving. So you can directly write your Kotlin code to the Android project, even the directory does not have to change, and then the program will be able to run normally, convenient to the eyes do not blink.

Other types of Android platforms tend to force you to learn a new language and the corresponding platform, with different programming paradigms, concepts and features. Kotlin is to let you write directly to the Android runtime class, as other Android programmers in Java written out of the same. In fact, the underlying API is the same, but the Kotlin organization is much better.

Remember when I threw my Android programming book last summer and didn't want to see it again? Now Kotlin makes me feel: is Android programming happy? I even think that maybe Android's bad API is probably not that bad, but Java is making it so disgusting.

Kotlin is committed to getting people to get around the nasty stuff of the Android API, and it's even better than IOS to give you the full experience you need. Well, at least it's better than objective-c, because I think Swift is certainly not bad. You know why? Because Swift and Kotlin are alike.

What is my favorite place to Kotlin?

Well, this topic is actually very big, I think I'd better write another article. Here I would like to mention those high-level (high-level) and common points.

  • Kotlin is much like Java. It's not as strange as Clojure or Scala (admitting reality, these two languages are strange). So you should learn Kotlin soon. This language is clearly written for Java developers.

  • It is more secure than Java. Java a lot of things that need annotation processors to do in Kotlin are built-in, such as overriding,nullability and so on. And Kotlin's rules for numerical conversions are more secure, although I don't like the way Kotlin is handled, but I'm thankful that this language forces me to think about my numerical representations.

  • Kotlin and Java can be translated into each other . It really means a seamless translation. I've seen a lot of JVM languages finally hang up because they don't support the subclass inheritance mechanism. I don't know when I'm going to use static internal classes, non-static inner classes, or any kind of broken stuff. Kotlin in the design of the translation of Java and the properties of the first place, that is, the Java translation to Kotlin can be gradual, one can directly convert a file.

  • Kotlin is very concise . You know I'm a golfer too, so I'm telling the truth. If everything is the same case, I prefer the short program as long as it writes the logic clearly. Kotlin is like a good game for me. On average, I found Kotlin's code was shorter than the same logical Jython code 5%-10% (which I measured with some sort of "gold standard"), and also guaranteed the readability and type safety of the program.

  • Kotlin closer to reality. Kotlin supports defining multiple classes in a single file, supporting first-class methods, operator overloading, extension methods, type aliases, string templates, and a bunch of language features that seem to be nothing new. And I just don't understand why Java doesn't support anything, and it doesn't even have the language features people need.

  • Kotlin evolved quickly . For example, the support for Coroutine, which has just been announced, will become an infrastructure that provides asyn/await, Geneator, and all other lock-free concurrency features.

  • Kotlin is very good at "take doctrine". Kotlin often copy ideas from other computer language designs and is not shy about it. They said: "We love the way C # is handled, so we're going to do it ourselves." ”

  • Kotlin supports DSLs. DSLs are not to be introduced, but they have to admit that the DSL is powerful. For example, if you look at Gradle's DSL and maven ratio, in a typical MAVEN project, the configuration code must be more than thousands of lines. So Kotlin is here to give you the pressure to work.

  • Kotlin's IDE is great in it . It was not long before I wrote the program file in Emacs, and Emacs reported a pair of errors. And I copy the same code into the IntelliJ, and then press Alt-enter to automatically fix more than 50, and then all the errors are taken care of. This is really a big help.

  • Kotlin is very interesting . I'm telling you, Kotlin is fun. Maybe this is my subconscious advertising. Kolint's keywords and method names are interesting. Kotlin me from a man who could only die programming. To convert to a computer language enthusiast.

Anyway, that's what you think: I packed my things and moved, and I met my neighbor Kotlin. I've seen a bunch of computer languages before, but only Kotlin, which allows me to rewrite my game server code in such a short period of time. And now I'm using Kotlin to rewrite everything I've written before.

I also know that many other programmers also feel very good about Kotlin and intend to become Kotlin programmers. Most of these people should be able to surpass me within 1-2 years. We talked about it privately and said to each other, "Kotlin makes programming feel good and it's back." "Not bad, Kotlin came before we lost all interest in programming. It's as if you've learned the grammar of language. This brings you back to the first time you've learned to program, and you feel like you're a good person, no matter what you write.

Once again, salute to JetBrains. They make a great contribution to the computer language! I'm off my hat.

So Kotlin is better than any other programming language you use? I think it's true for me. Because, if you happen to be using Java. If you spend the whole day writing Java in front of a chair, you'll find Kotlin is a clear stream. So let me know what you think of it.

Disclaimer: This article only explains my personal view of Android development and does not represent my employer (Google) or JetBrains's view.

Bole Online/programmers of those things excerpts from some comments in the original text:

Igor Tovstopyat-nelip

Good article!

JetBrains is not in the Czech Republic. Although it was established in Prague (Czech Republic), it was mainly in St. Petersburg. Many of their management and developers are Russians, many of them graduated from St. Petersburg University.

With regard to naming, the Java language is derived from the Java Islands in the Indonesian archipelago. Kotlin is an island in the Gulf of Finland, close to St. Petersburg. Peter the great robbed St. Petersburg from Sweden in the early 18th century. Since then, it has been the naval base of the Russian Baltic Fleet. St. Petersburg has a beautiful northern scenery, and the Naval Temple (Naval Temple) is impressive.

Our company (located in Atlanta) has tried multiple JVM languages, and Java is the first. Now we are more interested in Kotlin. We all like it very much. and Kotlin and Java are seamlessly interoperable.

Kotlin can also be compiled into JS, and it is worth mentioning that Kotlin Native is also in a fiery development, it looks like Rust's strong opponent.

Anonymous Netizen:

I used to use Eamcs and JetBrains Ides (Pycharm and Webstorm) together. Although this combination is strange, but surprisingly good. Emacs is suitable for mind-control level text editing, and the IDE is suitable for mouse-oriented loitering and minor modifications.

Stephen French:

I like C # and I'm really disappointed that Java is lagging behind too much because my work tends to be the JVM. Kotlin looks very interesting!

After reading this article has the harvest? Please share to more people

Follow "Android development picks", see Kotlin technical article return Sohu, see more

Editor

Why do you recommend using Kotlin language?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.