-
Notifications
You must be signed in to change notification settings - Fork 179
Kadai1,2 kotaaaa #87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kadai1,2 kotaaaa #87
Conversation
kadai1/kotaaaa/search/search.go
Outdated
@gosagawa
gosagawa
Nov 10, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
エラーはここで処理するのではなく、この関数を
func GetFiles(dir string, ext string) ([]string,error) {
とした上で呼び出し元で処理した方が良いです。理由としてはそのようにエラーハンドリングするのがGoの一般的な書き方であるほか、以下のような問題があるためです
- エラーのハンドリングを呼び出し元でコントロールできない
- この関数をCLI以外で使うときに中断されると困るケースがある
- ログを出したくないときに使いづらい
- log.Fatal(err)は内部でos.Exit(1)を呼び出すため、main()関数以外で使用すると他のゴルーチンの終了を待たずして大元であるmain()ゴルーチンを終了させてしまう
kadai1/kotaaaa/search/search.go
Outdated
@gosagawa
gosagawa
Nov 10, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
パスの結合はfilepath.Joinを使う方が良いでしょう。ディレクトリの区切りが/以外のプラットフォームでも対処できますし、ディレクトの最後に/がつくつかないで誤動作することがなくなります
kadai1/kotaaaa/search/search_test.go
Outdated
@gosagawa
gosagawa
Nov 10, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ここではGetFilesが意図どおりに動くかのテストをすべきかと思うので、拡張子が想定通りかを調べるよりファイル名が想定通りかを調べるほうが望ましいかと思います
kadai1/kotaaaa/search/search.go
Outdated
@gosagawa
gosagawa
Nov 10, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
細かいところになりますが、[]stringはarrayではなくsliceです([3]stringはarrayです)。変数名はarrではなく、slやlist,意味ある名前にするならtargetFilesとかresultsにするのが適切かと思います。変数名をどれにすべきかは場合によるのですが、とりあえずarrayは適切でなさそうとことを覚えておいてもらえると良さそうです
@gosagawa
gosagawa
Nov 10, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
入力と出力でどちらが問題なのかわかるように分けておいた方が親切かと思います
@gosagawa
gosagawa
Nov 10, 2021
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
名前が同じだとどちらがエラーとなったときにわかりづらいほか、1,2というように番号を振ってくと途中に追加するときに煩雑だったりどの番号がどのケースかがわかりづらいのでcaseNameを以下のようにわかりやすくつけとくと良いかと思います。
png to jpg
jpg to gif
jpg to svg
gosagawa
commented
Nov 10, 2021
kadai1/kotaaaa/converterにビルド済みのファイルがあげらていますが、これは環境毎に異なるものになりますし、ファイルサイズも大きいのでgitに含めない方が良さそうです
@gosagawa さん
丁寧にレビュー頂きありがとうございます!
一通り修正しました。勉強になりました。mm
Uh oh!
There was an error while loading. Please reload this page.
課題1を作成しました。
使い方については、READMEに記載しています。
お時間あれば、レビューをよろしくお願いします。
課題1
2021年11月06日追記
課題2 の単体テストの追加