Kotaro666-dev / android-project-refactoring

Apache License 2.0
1 stars 0 forks source link

ソースコードの可読性の向上 #1

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

本プロジェクトのソースコードはとても読みにくいです。下記のリストを参考に読みやすいように修正してください。

参考:https://kotlinlang.org/docs/coding-conventions.html

Kotaro666-dev commented 1 year ago

保存時にコードを最適化させる設定をする

https://qiita.com/chocomelon/items/46810763a5be0a433158

Kotaro666-dev commented 1 year ago

Coding conventions

クラス内のレイアウト

Companion object はクラス内レイアウトで一番下にくる

The contents of a class should go in the following order:

1. Property declarations and initializer blocks
2. Secondary constructors
3. Method declarations
4. Companion object

定数

定数はすべて SCREAMING_SNAKE_CASE で書く

Names of constants (properties marked with const, or top-level or object val properties with no custom get function that hold deeply immutable data) should use uppercase underscore-separated ([screaming snake case](https://en.wikipedia.org/wiki/Snake_case)) names:
const val MAX_COUNT = 8
val USER_NAME_FIELD = "UserName"

クラス内のプライベート変数名について

クラス内で 2 つの類似した役割の変数名がある場合の対応。 基本的には変数名にアンダースコアを使わない方針で行う。

If a class has two properties which are conceptually the same but one is part of a public API and another is an implementation detail, use an underscore as the prefix for the name of the private property:
class C {
    private val _elementList = mutableListOf<Element>()

    val elementList: List<Element>
         get() = _elementList
}

Immutability

// Bad: arrayListOf() returns ArrayList<T>, which is a mutable collection type
val allowedValues = arrayListOf("a", "b", "c")

// Good: listOf() returns List<T>
val allowedValues = listOf("a", "b", "c")

Default parameter values

Prefer declaring functions with default parameter values to declaring overloaded functions.

// Bad
fun foo() = foo("a")
fun foo(a: String) { /*...*/ }

// Good
fun foo(a: String = "a") { /*...*/ }

Loops on ranges

for (i in 0..n - 1) { /*...*/ }  // bad
for (i in 0 until n) { /*...*/ }  // good
Kotaro666-dev commented 1 year ago

各画面の命名を考える

1 枚目の画面

役割: 検索バーにキーワードを入力して、検索結果を表示する

SearchScreenFragment

2 枚目の画面

役割: 検索結果の詳細を表示する

SearchResultsDetailScreenFragment

Kotaro666-dev commented 1 year ago

XML 内の ID 命名規則

すべて小文字を使い単語の区切りはアンダースコアを使うこと

BEFORE

android:id="@+id/searchInputLayout"

AFTER

android:id="@+id/search_input_layout"
Kotaro666-dev commented 1 year ago

メモ

Local variable name '_viewModel' should start with a lowercase letter
Kotaro666-dev commented 1 year ago

対応内容が develop にマージされたため、本 ISSUE をクローズします。

Kotaro666-dev commented 1 year ago

新たに見つけた可読性の向上したい箇所の対応が完了し、develop にマージされたため、本 Issue をクローズします。