Twitter 運用 Kotlin 提高開發人員的工作效率和程式碼穩定性
透過集合功能整理內容
你可以依據偏好儲存及分類內容。

Twitter 是使用率最高的社群媒體平台之一,使用者可以隨時查看全球各地發生的情況。為此,工程團隊在 2017 年導入 Kotlin,目標是讓程式碼集更易於維護,Android 應用程式也因為 Kotlin 的空值安全功能而更可靠。
具體措施
該團隊最初將 Kotlin 引入 Periscope 的程式碼集和 Twitter 應用程式的 Periscope 功能,然後測試使用 Kotlin 的優點和取捨。我們改善了工作效率和程式碼穩定性,因此逐漸開始將 Kotlin 新增至 Twitter 應用程式的其他功能。
Kotlin 協助 Twitter 減少在應用程式中的程式碼量、減少樣板維護,並讓團隊發揮更大的生產力。他們使用資料類別、密封類別和預設參數等語言功能,不僅可撰寫較少的程式碼,也能加快速度。Kotlin 的智慧投放功能也減少了團隊需要編寫及維護的程式碼數量。
「使用 Kotlin 是很方便使用。樣板可以減少讓我們需要編寫的程式碼量。」- Twitter 資深軟體工程師 Andy Fox
Kotlin 的空值安全功能也提升了 Twitter 程式碼的可靠性。一開始,團隊導入 Kotlin 時發現了先前未偵測到的無訊息失敗情形。編譯時間空值檢查可讓團隊更快偵測問題,並以更主動的方式處理是否可為空值錯誤。
成果
採用 Kotlin 後,該團隊持續在自家應用程式中取得出色的系統健康狀態和效能。同時,他們在編譯時間 (而非執行階段) 偵測重大錯誤,從而提升團隊的工作效率,並使應用程式更安全。隨著工作效率和程式碼可靠性的提升,該團隊決定在 Kotlin 中編寫許多新功能,例如機群、DM 回應和清單。
開始使用
進一步瞭解如何使用 Kotlin 開發 Android 應用程式。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2020-10-21 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間: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)."]]