Skip to content

Conversation

@TORUS0818
Copy link
Owner

def normalize(email: str) -> str:
is_local_part = True
is_ignore_part = False
elements_of_normalization = []

Choose a reason for hiding this comment

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

他の単語がシンプルな分、elements_of_normalization という名前に違和感がありました。(長いな、何が入っているのかパッと分からなかったな)normalized_chars のような単語もありなのかなと思いました。

Copy link
Owner Author

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.

英語としても不自然に聞こえます。

Copy link
Owner Author

Choose a reason for hiding this comment

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

有難うございます。
あまり感覚がないので矯正していきたいです。

is_local_part = True
is_ignore_part = False
elements_of_normalization = []
for char in email:

Choose a reason for hiding this comment

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

予約語になり得る単語を変数名として使うのはよろしくないというコメントを、どこかで見た気がします。

Copy link
Owner Author

Choose a reason for hiding this comment

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

一応pythonでの予約語にはなっていない筈ですが、紛らわしいかもしれませんね。

normalized_local_part = local_part.split('+')[0]
normalized_local_part = normalized_local_part.replace('.', '')

return f'{normalized_local_part}@{domain_part}'

Choose a reason for hiding this comment

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

stringを作らないで、tupleで返してもよさそうです。

Copy link
Owner Author

Choose a reason for hiding this comment

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

確かに正規化されたメールアドレスを作る必要は必ずしもないですね。
有難うございます。

local = email.split('@')[0]
domain = email.split('@')[1]
if local.find('+') > 0:
local = local[:local.find('+')]

Choose a reason for hiding this comment

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

2回local.find('+')をしているのが気になります。

Copy link
Owner Author

Choose a reason for hiding this comment

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

そうですね。
1回インデックスを取得して使いまわせば良かったです。

def normalize(email: str) -> str:
is_local_part = True
is_ignore_part = False
elements_of_normalization = []

Choose a reason for hiding this comment

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

英語としても不自然に聞こえます。

def numUniqueEmails(self, emails: List[str]) -> int:
def normalize(email: str) -> str:
is_local_part = True
is_ignore_part = False

Choose a reason for hiding this comment

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

is_ignored_part
複数のループに分けた方が自然だと思います。

Copy link
Owner Author

Choose a reason for hiding this comment

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

fhiyoさんのコメントにもありましたね。
実装し直してみようと思います。

無駄なfindをしないように修正
パート毎に分けてループ処理する方式の実装を追加
- https://www.ietf.org/rfc/rfc1034.txt#:~:text=The%20labels%20must%20follow%20the%20rules%20for%20ARPANET%20host%20names.%20%20They%20must%0Astart%20with%20a%20letter%2C%20end%20with%20a%20letter%20or%20digit%2C%20and%20have%20as%20interior%0Acharacters%20only%20letters%2C%20digits%2C%20and%20hyphen.%20%20There%20are%20also%20some%0Arestrictions%20on%20the%20length.%20%20Labels%20must%20be%2063%20characters%20or%20less
- RFC5322
- https://datatracker.ietf.org/doc/html/rfc5322#:~:text=local-part%20%20%20%20%20%20%3D%20%20%20dot-atom%20/%20quoted-string%20/%20obs-local-part

Copy link

Choose a reason for hiding this comment

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

エンジニアというのはこういうところを普段から読んでいるので、「普段だったらリファレンスマニュアルや RFC を確認する」という発言は好意的に受け取られます。

@TORUS0818
Copy link
Owner Author

liquo-riceさん、goto-untrappedさん、odaさん、レビューをありがとうございました!

Comment on lines +73 to +74
> プログラムが停止する。
> エラーを示す値を返す。

Choose a reason for hiding this comment

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

@TORUS0818
”プログラムが停止する”の選択肢の場合って、何を返す想定でしょうか??

Copy link
Owner Author

Choose a reason for hiding this comment

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

例えば

email = '"@"@.com'
local_name, domain_name = email.split('@')

とかでValueError: too many values to unpack (expected 2)みたいな感じでしょうか。

Copy link

Choose a reason for hiding this comment

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

log Fatal を想定しています。よい並列計算ミドルウェアがあったりするとこれがよいケースがあります。

Copy link
Owner Author

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.

@TORUS0818
ありがとうございます。

ValueError: too many values to unpack (expected 2)

これで落ちちゃうとログを見に来た人は想定された終了なのか、意図しない異常終了なのか分からなくて焦ると思うので、親切なlog残して落ちて上げたほうがいいのかなと思いました!

Choose a reason for hiding this comment

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

@oda
ありがとうございます。

よい並列計算ミドルウェアがあったりするとこれがよいケースがあります

すいません。なぜここで並列計算ミドルウェアの話が出てくるんでしょうか(?? )

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます!
ここら辺の感覚、経験不足であまりないので意識していきたいと思います。

Copy link

Choose a reason for hiding this comment

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

現代のプログラム

Copy link

Choose a reason for hiding this comment

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

コードを書くときには、エンジニアリングをしてくださいと言っていますが、そもそもそのプログラムが何のために動いているかと、細かい動作をどうしたいかを接続することもそのエンジニアリングです。要は、大局観をもって行動して欲しいということです。それで、現代のプログラムは、人が起動して一つだけで動いている場合だけではないので、そうではない想定を考えてよしあしを決めてください。

Copy link
Owner Author

Choose a reason for hiding this comment

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

ありがとうございます。

実は現在の職場では(暗に)その真逆を求められています。。
書いたコードは基本他人は読まないし、責任は自分で持つ、細かいことに拘っている時間があるならその分早く結果(なんらかの数値や動くもの、という意味です)を出したほうが価値がある、という感じです。
(もちろん、もし同じスピードで、そのような配慮がなされたコードが書けるのならその方が良い、というのは合意していただけるとは思うのですが)

元々、上記のような状況に課題を感じて意識的に修正しようとはしていたのですが、まだまだ見えていないものが多いと感じます。皆さんと積極的にコミニュケーションして、この練習会でしっかり身につけられるよう頑張ります!

def numUniqueEmails(self, emails: List[str]) -> int:
unique_email_address = set()
for email in emails:
local_part, domain_part = email.rsplit('@', maxsplit=1)

Choose a reason for hiding this comment

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

Constraints に "Each emails[i] contains exactly one '@' character." とあるので、第二引数は書かなくても良いかもしれません。

Copy link
Owner Author

Choose a reason for hiding this comment

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

Comment on lines +169 to +171
local_part, domain_part = email.rsplit('@', maxsplit=1)
normalized_local_part = local_part.split('+')[0]
normalized_local_part = normalized_local_part.replace('.', '')

Choose a reason for hiding this comment

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

Python の文字列型は immutable なので、normalized_local_part を作るのに3つ値が宣言されますね。これを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.

有難うございます。
具体的にはどのようにすれば良さそうでしょうか。

Choose a reason for hiding this comment

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

他の方に同じコメントをしたら oda さんから返信がありました。ちゃんと見て後ほど返信しますが、仰られてる通りあまり適切でないレビューだった気がしています... すいません🙏
SuperHotDogCat/coding-interview#30 (comment)

Choose a reason for hiding this comment

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

有難うございます。
具体的にはどのようにすれば良さそうでしょうか。

上記 oda さんのコメントにもある通りおそらく遅くなってしまいますが... 以下のようにすればオブジェクトの生成数は減らせるかと思います

            local_part, domain_part = email.rsplit('@', maxsplit=1)
            normalized_local_part = []
            for char in local_part:
                if char == '+':
                    break
                if char != '.':
                    normalized_local_part.append(char)

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.

7 participants