Skip to content

Conversation

hroc135
Copy link
Owner

@hroc135 hroc135 commented Jul 23, 2024

Comment on lines +68 to +69


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここの空白は1行にした方がいいと思います。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8的には2行ですね。

Surround top-level function and class definitions with two blank lines.

https://peps.python.org/pep-0008/#blank-lines

Copy link

@seal-azarashi seal-azarashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全体的にとても読みやすくて良いコードだと思いました。

stack: List[str] = []
for i in range(len(s)):
if s[i] in brackets.keys():
if len(stack) == 0:
Copy link

@sakzk sakzk Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好みの問題だと思いますが、以下のように条件文をひとつづきにするのも自然に感じます。
(スタックが空か、もしくはスタックの頂上が目当てのものでないなら False )

if len(stack) == 0 or stack.pop() != brackets[s[i]]:
    return False

Copy link

@kazukiii kazukiii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

全体的に良さそうです。

- `if c in open_to_close.keys()`もより短く`if c in open_to_close`に変えた

```Python3
from queue import LifoQueue

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LifoQueueはスレッドセーフな設計になっていて、ロックを取得するためパフォーマンス面では劣りそうです。ユースケースによって使い分けるといいと思います。https://docs.python.org/3/library/queue.html

Comment on lines +68 to +69


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP 8的には2行ですね。

Surround top-level function and class definitions with two blank lines.

https://peps.python.org/pep-0008/#blank-lines

```

### Step 3
- `for i in range(len(s))`を`for c in s`に変えて、Pythonらしくシンプルさを追求した

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これ今回はどちらでもいいですが、例えばsがdeque等だった場合を考えると、ランダムアクセスがO(1)で出来ないので、場合によっては気をつけた方が良さそうです。

### Step 1
- stackのカテゴリの問題であるというヒントもあり、すぐに方針は立った
- 実装も割とすぐにできた
- 他のArai60の問題はgolangで解いてきたが、golangでの文字列処理は面倒なのでPythonを使うことにした

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[質問]
Goに詳しくないので質問させてください
Goのどのような部分が文字列処理を面倒にしていると思いますか??

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

goでは文字列に対してインデックスで一文字取得するとbyte型で、rangeでループするとrune型という別の型になります。
for i, c := range sとしてループの中でs[i]とcを出力すると、例えば'('の場合、どちらも41という出力結果になります。しかし、型が違うのでs[i] == cはエラーになってしまいます。一方、Pythonだとsもs[i]も同じstr型なので文字列の処理の際に余計なことを考えずに済むので今回はPythonを選びました。

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もう一つgoではなくpythonを選んだ大きな理由として、goにはスタックを自分で実装する必要があるからです。今回だとスタックからのpopを以下のようにやらないといけません。

l := len(openBracketsStack)
if l == 0 {
    return false
}
top := openBracketsStack[l-1]
openBracketsStack = openBracketsStack[:l-1]

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以上二つの理由から今回はgoを避けました。というより、面接で同じ問題が出されてgoを選んだらその時点で知識とセンスを疑われるような気がしたことが理由です。
以前勉強会で、面接で使う言語はその会社で使っている言語と必ずしも同じでなくて良いと伺いましたが、与えられた問題に対してどの言語を選ぶかというセンスは見られているでしょうか。

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

言語を切り替えられないこともありますし、何だと書きやすいという話をすれば十二分だと思いますね。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なるほど〜
標準ライブラリにデータ構造が乏しいのはGoにGenericsがなかったのも関係してるんですかね
サードパーティのライブラリ見てるとinterfaceでデータ構造を抽象化してるみたいですね
こっちが主流になっちゃって標準ライブラリのサポートがないままって感じなんでしょうか

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「サードパーティが主流になっちゃった」というより最初から標準で用意するつもりがなかったと思います。goはミニマリスト思考が大きなコンセプトになるので

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

G 社内であんまり困った記憶ないんですよね。ちょっと複雑なことをすると、RPC を飛ばすことになっていたかと思います。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

G 社内であんまり困った記憶ないんですよね。ちょっと複雑なことをすると、RPC を飛ばすことになっていたかと思います。

理解の確認をさせてください
これって、ある程度複雑なデータ処理は他のサービスをcallして任せていたからGo側の標準ライブラリにデータ構造が乏しくても困らなかったってことであってますか??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants