Twitter 使用 Kotlin 提高了开发者的工作效率和代码可靠性
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。

Twitter 是一个使用最广泛的社交媒体平台,在这里,用户可以随时了解世界各地正在发生的事情。Twitter 的工程团队于 2017 年引入了 Kotlin,目的是使用 Kotlin 的null 安全功能增强其代码库的可维护性和提升其 Android 应用的可靠性。
策略
该团队一开始将 Kotlin 引入 Periscope 的代码库以及 Twitter 应用的 Periscope 功能中,得以测试使用 Kotlin 的优势和折衷。生产力和代码可靠性的提升给该团队留下了深刻的印象,他们逐渐开始将 Kotlin 添加到 Twitter 应用的其他功能中。
Kotlin 帮助 Twitter 减少了其应用中的代码数量,最大限度地减少了样板维护,同时提升了团队生产力。该团队使用了数据类、密封类和默认参数等语言功能,这些功能减少了团队编写的代码量,并加快了编写代码的速度。Kotlin 的智能类型转换也减少了其团队需要编写和维护的代码量。
“使用 Kotlin 是一种乐趣。样板文件的缩减减少了需要编写的代码量。”- Twitter 高级软件工程师 Andy Fox
Kotlin 的 null 安全功能也提高了 Twitter 的代码可靠性。最初团队引入 Kotlin 时,他们发现了以前未检测到的无提示故障。编译时 null 检查可让团队更快地检测出问题,并更主动地处理可为 null 性错误。
成果
在采用 Kotlin 之后,该团队的应用持续展现出出色的系统运行状况和性能。与此同时,他们提高了团队的生产力,并在编译时(而非运行时)捕获严重错误来提高应用的安全性。随着生产力和代码可靠性的提升,该团队决定在 Kotlin 中编写多项新功能,例如队列、直接消息回应和列表。
开始使用
详细了解使用 Kotlin 开发 Android 应用。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2020-10-21。
[null,null,["最后更新时间 (UTC):2020-10-21。"],[],[],null,["# Twitter increases developer productivity and code reliability with Kotlin\n\n[Twitter](https://play.google.com/store/apps/details?id=com.twitter.android&hl=en)\nis one of the most widely used social media platforms where users can see what's\nhappening in the world at any given moment.\nThe engineering team introduced Kotlin in 2017 with the goal of making their\ncodebase more maintainable and their Android app more reliable as a result of\nKotlin's [null safety features](/kotlin/common-patterns#nullability).\n\nWhat they did\n-------------\n\nThe team initially introduced Kotlin into [Periscope](https://play.google.com/store/apps/details?id=tv.periscope.android&referrer)'s\ncodebase and into the Periscope feature of the Twitter app, and were able to\ntest the benefits and tradeoffs of using Kotlin. Impressed with the improvements\nto productivity and code reliability, they gradually began adding Kotlin to\nother features of the Twitter app.\n\nKotlin has helped Twitter decrease the amount of code in their app,\nminimizing boilerplate maintenance and **enabling the team to be more\nproductive.** They used language features such as data classes, sealed\nclasses, and default parameters, which allowed them to be able to write less\ncode, and faster. Kotlin's smart casting has also reduced the amount of code\ntheir team needs to write and maintain.\n\n*\"Kotlin is a joy to use. The reduction in boilerplate reduces the amount of\ncode we need to write.\" - Andy Fox, Senior Software Engineer at Twitter*\n\nKotlin's null safety features have also increased Twitter's code reliability.\nInitially when the team introduced Kotlin, they uncovered silent failures that\nhad previously gone undetected. Compile time null checking allows the team to\n**detect issues sooner, and handle nullability errors more\nproactively.**\n\nResults\n-------\n\nAfter adopting Kotlin, the team has continued to see excellent system health\nand performance for their app. At the same time, they've improved their team's\nproductivity and made their app safer by catching critical errors at compile\ntime instead of runtime. With the increases in productivity and code\nreliability, the team has decided to write many new features such as Fleets,\nDM Reactions, and Lists in Kotlin.\n\nGet started\n-----------\n\nLearn more about [developing an Android app with Kotlin](/kotlin)."]]