Conversation
hayashi-ay
reviewed
Mar 15, 2024
hayashi-ay
left a comment
There was a problem hiding this comment.
step1, step2は問題ないように思えます。target - numは変数化しても良いかなくらいでしょうか?
|
|
||
| 他の人の解法などを見て改善点を考える. | ||
|
|
||
| return None は type annotation と合わないので[]を採用することにした. 実務上本来どうするべきなのかはまだ分からない. |
There was a problem hiding this comment.
唯一の正解がある訳でなくて、実際はチームの方針などにもよるかなと思います。Noneが返ってくる場合がエラー、空配列が返ってくる場合がエラー、[-1, -1]のように返ってくる場合はエラーなどありますがある程度は決めの問題かなと思います。静的型付け言語などでは値でエラーを表すことが多い気がします。PythonだとNoneをエラーとしてしまっても良いように思います。
あとは他にも例外を投げちゃう方法やPythonだと関数の返り値が複数取れるのでいっそGo言語みたいに2番目の返り値でエラーかどうかを返してしまうという方法まで色々バリエーションがあります。一般的に例外だと大域脱出ができるので処理が簡単に書けますが、ソースコードを追いづらくなります。
Owner
Author
There was a problem hiding this comment.
早速レビューありがとうございます!
なるほど, いくつか選択肢がありその中からチームに合ったものを選ぶという感じなのですね. 確かにコードベースの中で作法が統一されていれば, 返り値がNoneだろうが[]だろうが親側のifがちょっと変わるぐらいの差ですもんね.
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.
Problem link