Kadai2 udomomo - #37
Open
Udomomo wants to merge 24 commits into
Open
Conversation
Udomomo
commented
Nov 23, 2018
| また、より効率の良い読み方を求めて新しいnewTail関数を作ったとしても、その関数以外の部分に手を加える必要がなく、リファクタリングが最小限で済む。 | ||
| このように、interfaceを上手に定義しておくことで、読む/書くための関数とそれ以外の関数をより疎結合に近い状態にしやすくなる。 | ||
|
|
||
| 上記はinterface一般にいえるメリットだが、io.Reader・io.Writerならではの良い点は、interfaceの中に定義されている関数が1つしかなく、それでいて意味的にも関数1つで過不足がないことにある。よけいな関数を定義しすぎてinterfaceが肥大化すると、後々そのinterfaceを使った新しいstructを定義するときに、必要性の薄い関数も改めて書かなければならず足を引っ張ることになりやすい。io.Reader・io.Writerは、Read/Write関数を定義しさえすれば使えるので、コードを書く側にとってもほとんど邪魔にならない。 |
Author
There was a problem hiding this comment.
ここは完全に主観なのですが、golangはinterface内のメソッドが少ない方が推奨されているのでしょうか?
Udomomo
commented
Nov 23, 2018
| # 課題2-2 | ||
| ## リファクタリング | ||
| - 画像変換の入り口のメソッドであるsearchFile関数に返り値を持たせた。 | ||
| - もともとは返り値を持たず、変換を実行するconvFile関数の返り値(=新しいパス)を最後にprintlnするだけだったが、新しいパス自体を返り値とする方が、searchFile関数の結果を取得してテストする処理を書きやすい気がした。 |
Author
There was a problem hiding this comment.
なんとなくですが、返り値がある方がテストしやすい気がしたのでこのようにしました。
Udomomo
commented
Nov 23, 2018
| func main() { | ||
|
|
||
| SUFFIX := []string{"jpg", "jpeg", "png", "gif"} | ||
| SEPARATOR := "." |
Author
There was a problem hiding this comment.
定数の定義のために大文字変数にしましたが、これはGolangでは一般的でしょうか?
Udomomo
commented
Nov 23, 2018
| log.Fatal("len of conv results is wrong") | ||
| } | ||
| return processedPaths | ||
| } |
Author
There was a problem hiding this comment.
SearchFileとsearchFileを分けたのは、単にテストのためだけです。
再帰関数で処理が終わった後の出力結果をテストしたいと思ったのですが、繰り返し実行されるsearchFile関数の結果を一箇所にためておく方法が思いつきませんでした。クラスがあればプロパティに貯めればよいのですが、Golangの場合はそれはできないので、SearchFIle関数を作りその中でprocessedPathをあらかじめ定義しておくようにしました。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
遅れましたが課題2です。
課題の解答はkadai2/README.mdに記載してあります。