3 ms·
I absolutely prefer strict typing myself. The issue becomes whether or not one thinks type coercion should be a thing. I'm personally against type coercion - b
by Nadya 11y ago
I absolutely prefer strict typing myself. The issue becomes whether or not one thinks type coercion should be a thing.
I'm personally against type coercion - but I also understand how it functions (and why it functions). I disagree with the "why" but as long as I understand the "how" I can avoid gotchas like string coercion. :)
Multiplication ( * ) and division ( / ) coerce to integers. Only + is used for strings, particularly concatenation. Personally I'm a fan of & being used for string concatenation and can't think offhand why not to use it, other than slight possibility of confusion over &&. However I'm not aware of a language that uses it.
>>"5" * 5
25
>>"5" * "5"
25
>>"5" / 5
1
>>"5" / "5"
1
- dumael 11y ago> I absolutely prefer strict typing myself. The issue becomes whether or not one thinks type coercion should be a thing. As a strong typing fanatic, I'd rather have the interpreter/compiler scream at me. In my opinion automatic type coercion is slightly less wrong than undefined behavior in C. (Aside, did you know that if GCC spots a statically provable null pointer deference, it will insert __builtin_trap() after the deference? I didn't know either until yesterday. This is acceptable because undefined behavior can mean "eat you hard drive".) If for strings '+' is concatenation, and '*' is for replication with '-' and "/" as exception behavior I can fully understand. (Admittedly '+' over '&' is either style or hard-core "the operation is different, therefore we need a different symbol choice"). Your example worries me. Personally I would not design a language like that. (Though I may have abused it in the past.)
- Nadya 11y ago>Admittedly '+' over '&' is either style or hard-core "the operation is different, therefore we need a different symbol choice The former more than the latter. The operation is different therefore we need a different symbol choice - and & also makes as much sense stylistically as + does. "string1" and "string2", when read, makes sense. & is different from the conditional && like piping | is different from the conditional or || >Your example worries me. Personally I would not design a language like that. Neither would I, but I like to think it was part of "made in 10 days" that allowed it to stick around.
- dragonwriter 11y ago> "string1" and "string2", when read, makes sense. & is different from the conditional && like piping | is different from the conditional or || Of course, in languages where & and | are already in use for bitwise operations on ints (etc.), using & for string concatenation would be a different form of the same clash as using + is.