本文へ移動
cccskills
無料GitHub で公開

kotlin patterns

Conventions for using Kotlin

日本語の概要は準備中です。原文の説明を表示しています。

インストール方法を見る

含まれるファイル(1)

  • SKILL.md3.6 KB

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

1. Remove usage of !! operator

The !! operator should be avoided in Kotlin as it can lead to NullPointerException at runtime. Instead, use safe calls (?.) or the let scope function to handle nullable values more gracefully.

2. Remove the safe call operator (?.) when possible

Using the safe call operator (?.) is a good practice, but it should be used judiciously. It makes no sense to use this operator when the value is guaranteed to be non-null, as it can lead to unnecessary null checks and reduce code readability.

3. Avoid using var when possible

In Kotlin, it is recommended to use val instead of var whenever possible. This helps to make the code more readable and maintainable, as it makes it clear that the value of a variable is not expected to change.

4. Use Duration overload when possible

Example 1

When using the delay function, it is recommended to use the overload that accepts a Duration parameter instead of a Long parameter. This makes the code more readable and easier to understand, as it clearly indicates the intended duration of the delay.

replace this:

delay(100)

with this:

delay(100.milliseconds)

Add import: import kotlin.time.Duration.Companion.milliseconds

5. Remove all code signatures

Code does not need to be signed. The code signature used to have some value, but in current times, the commit already has a signature. Old code may contain signatures that look like this:

/**
 * Created by joao on 28-4-16.
 */

They should all be removed, as they are not needed and add no value to the code.

6. When using Kotlin code make sure to use the kotlin extensions for parsing

Example 1

When finding this:

    .getForEntity("/tulips", String::class.java)

replace with:

    .getForEntity<String>("/tulips")

7. Update the usage of CSVParser which is now deprecated

This skill refers to the CSVParser from org.apache.commons.csv.*

Example 1

Replace

val csvParser = CSVParser(reader, CSV_HEADER)

with

val csvParser = CSVParser.builder()
    .setReader(reader)
    .setFormat(CSV_HEADER).get()

Example 2

Replace this

private val CSV_HEADER = DEFAULT
    .withHeader(
        "id",
        "description",
        "year",
        "value",
        "currency",
        "type",
        "diameterMM",
        "internalDiameterMM",
        "heightMM",
        "widthMM"
    )

with:

private val CSV_HEADER = CSVFormat.DEFAULT.builder()
    .setHeader(
        "id",
        "description",
        "year",
        "value",
        "currency",
        "type",
        "diameterMM",
        "internalDiameterMM",
        "heightMM",
        "widthMM"
    ).get()

8. For all uses of Lombok in Kotlin classes that still use its builder pattern, please convert them to data classes

Due to Java conversions to Kotlin, some of them, due to their automatic nature, didn't consider the existence of data classes. If Kotlin classes still use lombok for the builder pattern please convert them to data class.

9. Checklist

[ ] The code does not use the !! operator. [ ] The code does not use the safe call operator (?.) when the value is guaranteed to be non-null. [ ] The code uses val instead of var whenever possible. [ ] The code uses the Duration overload when using the delay function. [ ] The code does not contain any code signatures. [ ] The code uses the kotlin extensions for parsing when using Kotlin code. [ ] The code should not use the CSVParser constructuro directly

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

コメント

ログインなしで書き込めます。使ってみた感想、質問、動かなかった環境などを気軽にどうぞ。

まだコメントはありません。最初のコメントを書いてみませんか。

送信するとすぐに公開されます。メールアドレスや電話番号などの個人情報は書かないでください。URL は 2 つまでです。

0 / 1000 文字

このフォームは reCAPTCHA で保護されており、Google のプライバシーポリシーと利用規約が適用されます。

同じリポジトリのスキル

docker

無料

Conventions for docker

日本語の概要は準備中です。原文の説明を表示しています。

jesperancinha/whiskers-kotlin-native122026年7月20日 更新

Conventions for using in all JEE frameworks. These are common standards for CDI

日本語の概要は準備中です。原文の説明を表示しています。

jesperancinha/whiskers-kotlin-native122026年7月20日 更新

Conventions for using Java

日本語の概要は準備中です。原文の説明を表示しています。

jesperancinha/whiskers-kotlin-native122026年7月20日 更新

Conventions for using in all JVM languages

日本語の概要は準備中です。原文の説明を表示しています。

jesperancinha/whiskers-kotlin-native122026年7月20日 更新

ktor

無料

Conventions for Ktor Gradle modules

日本語の概要は準備中です。原文の説明を表示しています。

jesperancinha/whiskers-kotlin-native122026年7月20日 更新

Conventions for using parallelization in all tests using Jupiter

日本語の概要は準備中です。原文の説明を表示しています。

jesperancinha/whiskers-kotlin-native122026年7月20日 更新

jesperancinha のスキルをすべて見る

このスキルの問題を報告する