2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【公ド読】GitHub Copilot を使用したコードのリファクタリング

Posted at

【公式ドキュメントを読もうシリーズ】GitHub Copilot を使用したコードのリファクタリング

シリーズ概要

https://qiita.com/yasu_programming/items/cec66f9e8d5d571e9ce3

URL

https://docs.github.com/ja/copilot/using-github-copilot/guides-on-using-github-copilot/refactoring-code-with-github-copilot

説明

GitHub Copilot を使用したコードのリファクタリングの方法が書かれている。

非効率なコード -> 最適なコード

Can this script be improved?

繰り返し書かれているコード -> 関数化

move repeated calculations into functions

読みづらいコード -> 簡潔化

make this more concise

複雑なコード -> 分割して簡潔なコードに

split into 2 separate functions: one for cleansing data, the other for printing

可読性の低い条件式 -> 可読性の高い条件式

rewrite the condition to use a switch and use Java 21 syntax with null case, but also add documentation and provide a better function name

不適切なパラメータ -> 適切なパラメータ

use arrow notation and better parameter names

不適切なシンボル名 -> 適切なシンボル名、一括変更

これは一番の発見だった。
const members などの変数名にカーソルを置いてF2キーを押すと、別名の提案をしてくれる。
名前はプロジェクト全体でも変更されるようなので、慎重に使うべきだが、便利になるだろうなと思った。

所感

これ以上ないコードだったとしても、一度リファクタリングでGithub Copilotでリファクタリングしてもらうことで、既存のコードに新しいとらえ方ができるそうだなと思ったので、新規作成、更新などの作業のすべての最後の工程で、仮に何も変わらなかったとしても、Github Copilotでのリファクタリングの工程を挟んでもいいかもしれないと思った。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?