作者 | 张红月

出品 | CSDN(ID:CSDNnews)

近日,JetBrains 官博发文庆祝 Kotlin 十岁了,并制作纪念网站和视频来庆贺这一关键时刻。

2011 年 7 月 19 日,在 JVM 的编程语言峰会上,JetBrains 正式官宣 Kotlin 编程语言,一种新的 JVM 静态类型编程语言。Kotlin 已经从 Java 替代品发展成一个完整的生态系统,允许为不同需求的项目编写代码,包括服务器端、移动、Web 前端、数据科学,甚至多平台项目。

官方制作的庆贺网站分为三大部分,过去、现在、未来。基于时间轴分享 Kotlin 在过去取得了一些里程碑成就与事件。

Kotlin 十年回顾

下面我们一起乘坐时光机,看看 Kotlin 在从 2011 年到 2020 年都有哪些重要更新与高光时刻。

  • 第一篇 Hello World 官宣文章(https://blog.jetbrains.com/kotlin/2011/07/hello-world-2/)

  • 第一个语法类型

Function 类型 和 Function literals

//Functions
fun f(p: Int) : String { return p.toString() }
//Function types
fun (p: Int) : String, fun (Int) : String
//Function literals
{ (p: Int) : String => p.toString()} {(p : Int) => p.toString() }
{p => p.toString()}

高阶函数

fun filter<T>(
    c: Iterable<T>,
    f: fun (T) : Boolean
): Iterable<T>
val list = list("a", "ab", "abc", "") filter(list, { s => s.length() < 3 })

语法大改变,包括命名空间替换成关键词,使用“细箭”(->)取代 “肥箭”(=>),函数类型变得更具可读性。

// before:
fun max(col: Collection<Int>, compare: fun(Int, Int): Int): Int
// after:
fun max(col: Collection<Int>, compare: (Int, Int) -> Int): Int

Kotlin 的第一个Web 演示

  • 宣布正式开源

  • 正式在 Android 上运行

package com.example




import android.app.Activity
import android.os.Bundle




class HelloKotlin() : Activity() {
      protected override fun onCreate(savedInstanceState: Bundle?) {
          super<Activity>.onCreate(savedInstanceState)
          setContentView(R.layout.main)
      }
}
  • 使用 Kotlin 全面开发 Web 应用

  • 首个数据块的 SAM 转换

  • 添加新的语言特征:委托属性、可调用引用、静态常量和静态字段

  • 发布 Gradle 插件

  • Kotlinlang.org 成立

  • 添加新特性改善 JavaScript 互操作,添加 dynamic 关键字来支持动态声明,内嵌 JS 代码, IntelliJ IDEA 增加对 Kotlin 依赖注入支持。

jquery.getJSON(KotlinCommitsURL) { commits ->
  val commitsTable = jquery("#kotlin-commits")
  commits.forEach { commit ->
     commitsTable.append("""


                        ${commit.sha.substring(0, 6)}
                        ${commit.commit.message}
                    """)
  }
}
  • 改善开发体验,支持多个构造函数、伴随对象、密封类、lateinit 属性

class MyView : View {
    constructor(context: Context, attrs: AttributeSet, defStyle: Int): super(context, attrs, defStyle) {
    // ...
}




    constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) {}
}
  • 在 Kotlin 1.0 发布之前对语言进行重新修正,比如删除一些弃用项,摆脱在测试版期间发现的一些遗留字节码特性,移动一些 stdlib 代码,让包具有更多结构。

  • Kotlin 1.0 正式发布

  • 将 Kotlin 用于 Gradle 构建脚本的第一个里程碑

  • 协程首先出现

fun main(args: Array<String>) {
    val future = async<String> {
        (1..5).map {
            await (startLongAsyncOperation(it)) // suspend while the long method is running
        }.joinToString(" ")
    }
    println(future.get())
}
  • 第一个 Kotlin 之夜在旧金山举行

图源:https://kotlinlang.org/

  • Kotlin 成 Android 官方支持语言

  • Kotlin 用户组支持计划启动,Kotlin Nights 成为社区驱动的系列活动

  • Kotlin 1.1 发布

  • Kotlin 首本书籍面世

  • Kotlin/Native 的第一个技术预览上线

  • 第一届 KotlinConf 在旧金山举行

  • Kotlin 1.2 发布

  • Kotlin 框架 Ktor 1.0 发布

  • 内联类可以在不创建实际包装对象的情况下包装某种类型的值

1 inline class Name(internal val value: String)
  • Kotlin 1.3 发布

  • Kotlin 可以嵌入到文章等相关素材中

<script src="https://unpkg.com/kotlin-playground@1" 
data-selector="code"></script>
  • KotlinConf 2018 在阿姆斯特丹举行

  • Kotlin 成 Android 首选编程语言

  • 为 Kotlin 类实现了 SAM 转换

fun interface Action {
    fun run()
}
fun runAction(a: Action) = a.run()
fun main() {
    runAction {
        println("Hello, KotlinConf!")
    }
}
  • 首个 Kotlin Heroes 竞赛在 Codeforces 上举行

  • KotlinConf 2019 在哥本哈根举行

  • Kotlin Multiplatform Mobile 移至 Alpha

  • Kotlin 1.4 发布

  • Andrey Breslav 下台,Roman Elizarov 成为 Kotlin 的新项目负责人

  • Kotlinx.serialization 1.0 发布

  • 宣布了 Kotlin 和 Kotlin 插件的新发布节奏,Kotlin 1.X 每六个月发布一次

  • 《Atomic Kotlin 》一书面世

以上是 Kotlin 从出生到 2020 年的一些主要变化。

现在

当前 Kotlin 的最新稳定版本为 1.5.21,具体特征及教程,感兴趣的同学可以前往:https://kotlinlang.org/docs/home.html 查看。

未来计划

除了回顾过去和介绍当下,Kotlin 项目负责人 Roman Elizarov 还介绍了 Kotlin 的一些未来计划。主要分为以下几大块:

  • 打造 Kotlin 为多平台的编程语言

  • 结构数据

  • 代码安全,不变性

  • 新编译器

  • 元编程

  • 更多静态类型

最后,我们祝 Kotlin 10 岁生日快乐,作为开发者,你对 Kotlin 有哪些祝福跟期许呢?

参考链接:

  • https://blog.jetbrains.com/kotlin/2021/08/ten-years-of-kotlin/

  • https://kotlinlang.org/lp/10yearsofkotlin




☞小鹏汽车副总裁纪宇:坚持智能化技术自研,打造最深的护城河
☞程序员因开发速度太慢而遭公司起诉,索赔金额高达90万!☞字节跳动教育裁员:赔付方式N+2;英特尔全新至强W-3300处理器发布;VS Code 1.59发布|极客头条
Logo

20年前,《新程序员》创刊时,我们的心愿是全面关注程序员成长,中国将拥有新一代世界级的程序员。20年后的今天,我们有了新的使命:助力中国IT技术人成长,成就一亿技术人!

更多推荐