Skip to content
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

hex APIの変更の提案 #565

Open
marihachi opened this issue Feb 10, 2024 · 10 comments
Open

hex APIの変更の提案 #565

marihachi opened this issue Feb 10, 2024 · 10 comments

Comments

@marihachi
Copy link
Contributor

marihachi commented Feb 10, 2024

hex APIの変更の提案

現行API

@Num:to_hex(x: num): str
@Num:from_hex(hex: str): num

方針

  • 配列を16進文字列(hex)にする用途の方が多そう
    • 数値単体をhexにする用途はあまりないと思われるが、無くはなさそう
  • プリミティブプロパティを積極的に使う

新API

  • 各オブジェクトにあるto_hexでhexを生成する基本コンセプト
  • 文字列からはstd関数を使って配列に変換できる
@(v: num).to_hex(): str
@(v: arr<num>).to_hex(): str
@Arr:from_hex(hex: str): arr<num>
@marihachi marihachi changed the title hex APIの変更 hex APIの変更の提案 Feb 10, 2024
@FineArchs
Copy link
Member

@Arr:from_hex(hex: str): arr<num>

数値の境目は何で区切る感じですか?

@salano-ym
Copy link
Member

桁が決まっているわけではないので使い勝手は良くない気がします

@marihachi
Copy link
Contributor Author

marihachi commented Feb 10, 2024

2桁ずつ(0~255)の区切り文字なしで考えてます
確かに区切り文字は考えてなかったです

@marihachi
Copy link
Contributor Author

32bitの値をhexで表示したい場合などの要求は満たせないですね..

@marihachi
Copy link
Contributor Author

marihachi commented Feb 10, 2024

こうですかね?

案2

@(v: num).to_hex(): str
@Num:from_hex(hex: str): num // 変更なし

@FineArchs
Copy link
Member

to_hexだけプリミティブプロパティ化する感じですね。
正直@Num:from_hex(hex: str): numの名前空間が引数ではなく返り値の型になっている点が気になりますが、Strにすると更に違和感が大きくなる気がするので特例でNum:でもいいと思います。

@marihachi
Copy link
Contributor Author

marihachi commented Feb 10, 2024

候補としては

  • @Num:from_hex(hex: str): num
  • @Hex:to_num(hex: str): num

ですかね

@FineArchs
Copy link
Member

@Hex:to_num(hex: str): num

これ一つのために名前空間を作るのか…という気はしますね

@salano-ym
Copy link
Member

numの生成」に視点を置くならNumでいいと思います
名前空間は引数がどうかより意味的にどこに所属すべきかで考える方がしっくり来ます

@FineArchs
Copy link
Member

まあ@Num:from_hex(hex: str): numでよさそうですかね

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

No branches or pull requests

3 participants