by Adam Arold

亚当·阿罗德(Adam Arold)

超越Android:探索Kotlin的应用领域 (Going beyond Android: exploring Kotlin’s areas of application)

If you have written something in Kotlin, chances are that you wrote it for Android. Kotlin, however, has other areas where it can be useful. In the following series, we’ll explore in what other fields Kotlin can shine and discuss how you can take advantage of them.

如果您使用Kotlin编写过某些内容,则很可能是您为Android编写的。 但是,Kotlin在其他领域可能会有用。 在以下系列中,我们将探讨Kotlin在其他领域可以发挥的作用,并讨论如何利用它们。

Even though Kotlin started out as a language for the JVM, its creators have started to give us options for using the language on other platforms as well. The Kotlin Frontend Plugin is nothing new, but now we can go native or create multiplatform projects.

即使Kotlin最初是作为JVM的一种语言,它的创建者也开始为我们提供在其他平台上使用该语言的选择。 Kotlin前端插件并不是什么新鲜事物,但是现在我们可以使用本机或创建多平台项目了 。

What is also interesting is that on the JVM you can also use Kotlin on the backend with great effect. Using Spring with Kotlin is becoming easier with the advent of Spring 5 which has built-in support for Kotlin, but you can choose from a variety of technologies, like vert.x, RxKotlin or even tools written in Kotlin like Hexagon.

同样有趣的是,在JVM上,您也可以在后端使用Kotlin,效果非常好。 随着Spring 5的内置支持 ,Spring与Kotlin结合使用变得越来越容易,但是您可以选择多种技术,例如vert.x , RxKotlin或什至是用Kotlin编写的工具(例如Hexagon) 。

后端的Kotlin (Kotlin on the backend)

As I have written before, I think that the interop between Java and Kotlin is quite seamless. This also means that using Kotlin in place of Java on the backend is rather easy. Apart from a few nuisances, you can pretty much start writing your new features in Kotlin within your Java project. Or if you just want to try it out, you can start by writing your tests with it.

正如我之前写的 ,我认为Java和Kotlin之间的互操作是相当无缝的。 这也意味着在后端使用Kotlin代替Java很容易。 除了一些麻烦之外,您几乎可以开始在Java项目中的Kotlin中编写新功能。 或者,如果您只想尝试一下,则可以开始编写测试。

If you look around, it seems that companies with a big slice of the backend pie also have the same thought: the new version of Spring has some features dedicated to Kotlin, and you can even use Kotlin to write your Gradle scripts using the kotlin-dsl.

如果环顾四周,似乎后端派中有很大一部分的公司也有相同的想法:Spring的新版本具有一些Kotlin专用的功能,您甚至可以使用Kotlin使用kotlin-编写Gradle脚本- dsl 。

What is interesting to note here is that you don’t need Kotlin support for any of these libraries, because the Java interop features of Kotlin are so good. In the next article in this series, we’ll explore how you can write backend code with and without libraries written in Kotlin. We’ll also look into how you can tinker with your existing programs written in Java.

这里有趣的是您不需要这些库中的任何一个Kotlin支持 ,因为Kotlin的Java互操作性非常好。 在本系列的下一篇文章中,我们将探讨如何使用和不使用Kotlin编写的库来编写后端代码。 我们还将研究如何修改Java编写的现有程序。

将Kotlin编译为Javascript (Compiling Kotlin to Javascript)

When trying to compile Kotlin to Javascript, you have two options: the kotlin2js plugin and the kotlin-frontend-plugin.

尝试将Kotlin编译为Javascript时,您有两个选择: kotlin2js插件和kotlin-frontend-plugin

The former is a simple way to turn your code to JS without the hassle of managing external dependencies. It just works out of the box and results in a .js file which you can copy to your static assets folder.

前者是将代码转换为JS的简单方法,而无需管理外部依赖项。 它开箱即用,并生成一个.js文件,您可以将其复制到静态资产文件夹中。

The latter is a little more involved, but it lets you use both Maven and npm dependencies.

后者要复杂一些,但是它可以让您同时使用Maven和npm依赖项。

With the use of these, you can easily go full stack — but they do not let you share code between your backend and your frontend project. Check out this TodoMVC implementation which I have written if you are interested in how this works.

使用这些功能,您可以轻松地进行完整堆栈处理-但是它们不允许您在后端项目和前端项目之间共享代码。 如果您对此工作原理感兴趣,请查看我编写的此 TodoMVC实现。

走向本土 (Going native)

Have you ever tried running Kotlin in an embedded environment or compiled it into a single binary? Enter Kotlin Native which lets you do just that:

您是否曾经尝试过在嵌入式环境中运行Kotlin或将其编译为单个二进制文件? 输入Kotlin Native,您可以执行以下操作:

Kotlin/Native is an LLVM backend for the Kotlin compiler, runtime implementation, and native code generation facility using the LLVM toolchain.

Kotlin / Native是LLVM后端,用于LLVM工具链的Kotlin编译器,运行时实现和本机代码生成工具。

While this is still in a pre-release version (0.4 at the time of writing) Kotlin Native is a promising development. It tries to fill in the holes which are currently present, and lets you use Kotlin in some areas where it was not feasible to do so, like:

尽管它仍处于预发行版本中(在撰写本文时为0.4 ),但Kotlin Native是一个有前途的开发。 它尝试填补当前存在的漏洞,并让您在不可行的某些区域使用Kotlin,例如:

  • iOS applications (reusing code with Android)
    iOS应用程序(在Android中重用代码)
  • Embedded systems/IoT (e.g., Arduino and beyond)
    嵌入式系统/物联网(例如,Arduino和更高版本)
  • Data analysis and Scientific Computing
    数据分析与科学计算
  • Server-side and Microservices (low-footprint executables, utilizing the power of coroutines)
    服务器端和微服务(占用空间较小的可执行文件,利用协程的强大功能)
  • Game Development
    游戏开发

多平台项目 (Multiplatform projects)

While it is all well and good that you can now use Kotlin on a multitude of platforms, what good does it do if you can’t wire your different codebases together? With the release of Kotlin 1.2, you can now share code between platforms reliably.

虽然现在可以在多种平台上使用Kotlin很好,但是如果您不能将不同的代码库组合在一起又有什么用呢? 随着Kotlin 1.2的发布 ,您现在可以在平台之间可靠地共享代码。

This works by dividing your codebase into common and platform modules and by using the expect + actual API. This lets you define classes and functions which will be implemented on each platform. You can take a look at this video by Dmitry Jemerov, who is the Kotlin IDE Team Lead at JetBrains, to get a better understanding of this topic.

通过将您的代码库划分为通用模块和平台模块,并使用Expect +实际 API,可以实现此目的。 这使您可以定义将在每个平台上实现的类和函数。 您可以观看JetBrains的Kotlin IDE团队负责人Dmitry Jemerov的这段视频 ,以更好地理解这一主题。

结论 (Conclusion)

We’ve explored some areas where Kotlin can shine as well as how you can glue together your multiplatform projects. In the next articles, we’ll look into each of these options in a little more detail.

我们探索了Kotlin可以发挥作用的一些区域,以及如何将多平台项目粘合在一起。 在下一篇文章中,我们将更详细地研究每个选项。

Thanks for reading! You can read more of my articles on my blog.

谢谢阅读! 您可以在我的博客上我的文章。

翻译自: https://www.freecodecamp.org/news/beyond-android-exploring-kotlin-areas-of-application-5d28ff66a446/

超越Android:探索Kotlin的应用领域相关推荐

  1. 超越Android:Kotlin在后端的工作方式

    by Adam Arold 亚当·阿罗德(Adam Arold) 超越Android:Kotlin在后端的工作方式 (Going Beyond Android: how Kotlin works on ...

  2. kotlin跨平台_探索Kotlin跨平台第1部分

    kotlin跨平台 介绍 (Introduction) Kotlin makes Android development more fun. If you search the web, you'll ...

  3. 【译】探索 Kotlin 的隐性成本(第三部分)

    本文讲的是[译]探索 Kotlin 的隐性成本(第三部分), 原文地址:Exploring Kotlin's hidden costs - Part 3 原文作者:Christophe B. 译文出自 ...

  4. 探索Kotlin的隐性成本

    转载 自 探索Kotlin的隐性成本 2016年, Jake Wharton发表了一系列有趣的言论关于Java的隐性成本.同一时期他也开始拥护使用Kotlin开发Android,但是几乎不提Kotli ...

  5. 探索Kotlin的隐性成本-2

    原文转自探索Kotlin的隐性成本-2 第二部分将继续Kotlin编程语言,如果未读第一部分,请先阅读part 1. 让我们重新审视幕后并且发现更多的实现细节关于Kotlin特性. Local fun ...

  6. kotlin ++ --_顺便说一句-探索Kotlin代表团

    kotlin ++ -- by Adam Arold 亚当·阿罗德(Adam Arold) 顺便说一句-探索Kotlin代表团 (By the way - exploring delegation i ...

  7. [Android]使用Kotlin开发Android(二)

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/4829007.html [TOC] 使用Kotlin+OkHtt ...

  8. Android探索之旅 | 面向对象和Java基础

    -- 作者 谢恩铭 转载请注明出处 上一篇 Android探索之旅 | Android简介 中说到: "Android的默认开发语言是Java,入门简单.而且,你的Java水平不需要多好就可 ...

  9. 用Kotlin开发您的第一个应用程序| Android与Kotlin

    In the previous article, we learned how to setup Kotlin in the android studio? Now moving to journey ...

最新文章

  1. CSS3初体验之奇技淫巧
  2. 官方推荐!用TensorFlow 2.0做深度学习入门教程
  3. 利用 Android Studio 和 Gradle 打包多版本APK
  4. [armv8-arch64]linux kernel 5.9的异常量表介绍(irq,fiq,sync,svc)
  5. Python中的向量、矩阵(numpy)
  6. html5基础知识点文本标签
  7. oracle安装及卸载总结
  8. DockerFile 入门到精通
  9. java整数翻转_Java程序反转数字
  10. 好程序员前端教程之JavaScript闭包和匿名函数的关系详解...
  11. 网站性能测试工具--MS Web Application Stress Tool
  12. Linux Bash严重漏洞修复紧急通告
  13. 深入探索 Android 包体积优化(匠心制作)
  14. java读取excel模板并复制_POI复制Excel模板并填充数据
  15. pandas入门(一):pandas的安装和创建
  16. ipad wifi信号测试软件,iPad3的wifi信号弱 二种方法修复WiFi信号
  17. 跨域 SameSite secure
  18. 百度不收录网站的原因
  19. [新星计划] Python环境搭建 | 万丈高楼平地起
  20. Python发送验证码短信

热门文章

  1. Redis面试复习大纲在手面试不慌,内含福利
  2. js 触发LinkButton点击事件,执行后台方法
  3. 关于网页授权的两种scope的区别说明
  4. 微信企业号第三方应用开发[一]——创建套件
  5. JavaWeb项目前端规范(采用命名空间使js深度解耦合)
  6. 通过mod_limitipconn模块来限制apache的并发连接数
  7. ASP.NET应用程序客户端执行的优化小技巧
  8. C#怎么用代码模拟手机去访问手机网站抓取数据
  9. 利用jdk自带的运行监控工具JConsole观察分析Java程序的运行 Jtop
  10. 医动力Android基于CC组件化框架的探索与实践