News for hackers. Stuff that matters.
Re:My Opinion on “5” == 5 by crote on Thursday July 29, 2021 @01:14PM (#27998823)
On the other hand, what about "V" == 5? Or one of the literally dozens of unicode characters representing the number five in different writing systems? Maybe even "five" == 5?

Accepting both a numerical user id and a username string is a very valid scenario. However, I believe you should handle that by explicitly trying to parse it as a number, not hoping that automatic coercion will do the right thing. It's just a footgun waiting to go off.

Re:My Opinion on “5” == 5 by infogulch on Thursday July 29, 2021 @01:37PM (#27999092)
Good point.

    "5" == 5
    "⑤" == 5
    "⑸" == 5
    "⁵" == 5
    "𝟝" == 5
    "𝟓" == 5
    "𝟻" == 5
    "V" == 5
    "Ⅴ" == 5
    "𝍸" == 5   # https://unicode-table.com/en/1D378/
    "𐄋" == 5   # https://unicode-table.com/en/1010B/
    "৫" == 5    # https://unicode-table.com/en/09EB/
If you think the first should work, you should justify why the others shouldn't.
Re:My Opinion on “5” == 5 by tetha on Thursday July 29, 2021 @01:35PM (#27999061)
> Accepting both a numerical user id and a username string is a very valid scenario. However, I believe you should handle that by explicitly trying to parse it as a number, not hoping that automatic coercion will do the right thing. It's just a footgun waiting to go off.

This is why many people recommend questioning the use of basic or naked types. Details vary between the language, but this should be a type UserID with a UserID::from(String) and maybe a UserID::from_symbolic_name(String) and everything but some edge code should work on UserIDs. This makes code easier to read, too.