Kotlin の採用により、コード行を 20% 減らし、開発チームの士気も高めたスマートニュース
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。

SmartNews は、多様なニュース提供元からのタイムリーなニュースを共有することで、毎日何百万人もの人々が世界の出来事を見つけられるよう支援しています。同社は 2012 年に日本で創業し、現時点でのダウンロード数は 5,000 万件を超えています。
2019 年 6 月、Android のアプリ開発の主軸が Kotlin に移行しつつあると判断した開発チームは、Kotlin を検討することを決めました。Kotlin 採用の決め手となったのは、Kotlin メインの Jetpack ライブラリを活用できること、コード量を減らして保守の負担を軽減できること、構文の表現性が高く理解しやすいことなどでした。
スマートニュース社の取り組み
スマートニュース社の開発チームは Java に精通していたため、Kotlin でのコーディングに難しさを感じることはありませんでした。Kotlin は Java との 100% 相互運用性を備えているので、既存のコードベースで作業しながら、Kotlin で気象レーダーやニュースなどの新機能の作成を簡単に開始できます。雨雲レーダー機能(特許取得済み)では、コルーチンを使用して画像のダウンロードとキャッシュを管理することにしました。コルーチン ディスパッチャでタスクの管理を抽象化することで、raw スレッドの管理に伴うピットフォールを避けることができました。
一部の Java コードをリファクタリングした開発チームは、Kotlin の null 安全性機能に感銘を受けました。Kotlin の構文では可変性、null 可能性、初期化を特定できるため、早い段階でエラーを捕捉できます。これにより、コード変更の検証にかかる時間を 10% 短縮することができました。Kotlin の簡潔で効率的な構文を使用することで、コードベースの読みやすさが向上して保守が容易になり、ビジネスの継続的な成長にも対応できる見通しが立ちました。
結果
Kotlin を採用したことにより、実装から公開までの全体的な生産性が向上しました。最大の改善点は、Kotlin で記述したことでコード行を 20% も削減できたことです。SmartNews アプリのコードはすでに半分ほどが Kotlin に移行しています。新機能はすべて Kotlin で記述することにしているほか、既存のコードのリファクタリングを進めてさらに保守性を高めることにしています。
Kotlin を実装し、ボイラープレート コードを削減する過程で、開発チームの士気も向上しました。メンバーがそれぞれのアイデアをより効率的に表現できるようになり、各自が将来のために読みやすいコードを心がけるようになりました。スマートニュース社でエンジニアリング マネージャーを務める大橋英雄氏によれば、Kotlin はエンジニアの募集採用にも効果的だといいます。「応募者から最も多い質問のひとつが、"Kotlin は使っていますか?どれくらい活用していますか?" というものです。多くのエンジニアが Kotlin への移行に関心を寄せており、弊社としてもこの動きを支援したいと考えています。」開発チームの士気向上や募集採用への好影響は、Kotlin の採用を決めた主たる理由ではありませんでしたが、競争が激しいこの業界で成長し続けるために必要なポジティブな変化をもたらしてくれました。
始める
詳細については、Kotlin で Android アプリを開発するをご覧ください。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2021-01-06 UTC。
[[["わかりやすい","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"]],["最終更新日 2021-01-06 UTC。"],[],[],null,["# SmartNews reduces lines of code by 20% and improves team morale with Kotlin\n\n[SmartNews](https://play.google.com/store/apps/details?id=jp.gocro.smartnews.android)\nhelps millions of people discover their world everyday by sharing timely news\nfrom a diverse set of news sources. The company was founded in 2012 in Japan,\nand it now has over 50 million downloads globally.\n\nIn June 2019, the team saw Android development moving towards Kotlin first and\ndecided to start testing Kotlin themselves. They wanted to take advantage of\nKotlin-first Jetpack libraries, reduce the amount of code they had to maintain,\nand benefit from Kotlin's expressive and easy-to-understand syntax.\n\nWhat they did\n-------------\n\nThe team at SmartNews is well versed in Java, so it was fairly easy for them to\nstart writing in Kotlin. As Kotlin is 100% interoperable with Java, they could\neasily start writing new features such as\n[Weather Radar and News From All Sides](https://about.smartnews.com/en/2020/09/17/20200917/)\nin Kotlin, while working in their existing codebase. They used coroutines to\nmanage image downloading and caching within the patented Weather Radar feature.\nCoroutine dispatchers provide a useful abstraction for managing tasks, and this\nhelped the SmartNews engineers avoid the pitfalls that come from managing raw\nthreads.\n\nThe team also refactored some of their Java code, and was impressed with\nKotlin's null safety features. Kotlin's syntax for identifying mutability,\nnullability, and initialization helped the team catch errors early on,\nand **reduced the amount of time to review code changes by 10%**.\nUsing Kotlin's succinct and efficient syntax, they were also able to increase\nthe readability of their codebase, which has made their code easier to maintain\nas the company continues to grow.\n\nResults\n-------\n\nWriting in Kotlin has **improved their overall productivity from\nimplementation to launch** . The biggest improvement they saw was that\nwriting in Kotlin **reduced their converted lines of code by 20%**.\nApproximately half of the SmartNews app is currently in Kotlin, and the\ndevelopment team plans on writing all new features in Kotlin as well as\nrefactoring some of their existing code in order to continue increasing their\ncode maintainability.\n\nAs the development team was implementing Kotlin and reducing boilerplate code,\nthey noticed an **increase in team morale** . The team was excited\nto be able to express their ideas in a more efficient way, and have their code\nbe more readable for the future. Hideo Ohashi, the Engineering Manager for\nSmartNews noticed **Kotlin has helped their engineering recruiting\nefforts** . *\"The most frequent questions from candidates are 'are you\nusing Kotlin? How often do you use it?' It seems now that many engineers are\ninterested in migrating to Kotlin and want to support it.\"* While these\nimprovements in team morale and recruitment were not the main reasons the team\nadopted Kotlin, these positive changes will help the company as it continues to\ngrow in this competitive industry.\n\nGet started\n-----------\n\nLearn more about [developing an Android app with Kotlin](/kotlin)."]]