If you want to compare input to an int, you should be verifying the input is a valid int before comparing it.
Just hoping the language will do the right thing is a great way to inadvertently allow exploits in your service
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.
"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.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.
People usually understand the difference between "cat" and a cat.
So "5" + 1 is 6, just as 5 + 1 is 6.
Perl uses .
Oracle SQL uses ||
Microsoft SQL and VBA use &
C obviously doesn't use +.
Neither does Pascal.
Power Query doesn't.Nope, Microsoft SQL uses +.
* https://docs.microsoft.com/en-us/sql/t-sql/language-elements...
* https://i.imgur.com/7z81o8t.png
* https://i.imgur.com/VDR9qer.png
> C obviously doesn't use +.
But C++ does for std::string.
> Neither does Pascal.
Original Pascal didn't, but I think most modern Pascals do (e.g. Object Pascal known from Delphi).
I was referring to Access.
>Original Pascal didn't, but I think most modern Pascals do
I'm pretty sure concat() was used in THINK and Metrowerks Pascal in the 90s.
VBA (and VB in general) overloads "+" for strings in addition to providing "&", the difference being mostly in what gets converted to what in various situations: https://docs.microsoft.com/en-us/office/vba/language/referen...
Python and Ruby even overload *, for the dubiously useful construction:
"hello" * 3 == "hellohellohello"
For the most part, the developers in those spaces seem to know the pitfalls and how to avoid them.
I’d argue that there are some valid use cases for “5” and 5 to be equal. For example, if you take user input where on an admin screen for a user ID or username, you don’t know if the type is a string or number. Another common example is when you don’t have a known encoding for a packet yet, so you treat it as a binary string. In these cases, it’s easier to grok, as a human what is expected.