4 ms·
C throws a warning, because you need to manually cast to get expected behavior. But it does not behave the same as javascript, try it yourself, you will not get
by kamranjon 4y ago
C throws a warning, because you need to manually cast to get expected behavior. But it does not behave the same as javascript, try it yourself, you will not get "44" when you add "4" to 4.
Go does not support implicit type conversion, so no it does not behave the same as Java or Javascript, and will throw an error.
Rust does not allow adding an integer to a string and will also throw an error.
I suggest actually trying these things yourself, we are talking about adding an integer to a string, or subtracting an integer from a string. Obviously many languages will throw an error when trying to do this.
- cxr 4y ago> C throws a warning [sic] No, it doesn't. Nor does it throw an error. Once again: C does not even have the infrastructure to throw. Not just when adding numbers and strings, but anything. Ever. In any circumstance. > it does not behave the same as javascript Who said it did? > I suggest actually trying these things yourself Likewise (especially if you're going to be condescending about it). > Obviously many languages will throw an error when trying to do this. That's not obvious. I've asked you for examples, and you've named multiple ones that definitely don't. (And this is not an attempt to be rude, but rather frank: at this point in the discussion you come across as someone who, despite having probably used several handfuls of languages including the ones you mention, has a lot of confidence but only a coarse understanding and/or loose appreciation of the relevant concepts at play—down to confusing the distinction between compile-time vs run-time behavior.)
- kamranjon 4y agoC: "4" + 4 = 8 warning: assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast Go: "4" + 4 invalid operation: "4" + 4 (mismatched types untyped string and untyped int) Rust: "4" + 4 error[E0369]: cannot add `{integer}` to `&str` Listen - you can argue semantics all you want but unless you try these things yourself, we're not going to get anywhere. You asked me for examples of non-dynamic languages that don't behave the same as javascript, I provided them. I feel like maybe you took my suggestion to actually try these things out as condescending, it wasn't, I was trying to be constructive. This is a discussion about what languages allow you to do, compile-time vs run-time is irrelevant, if we get a warning or an error at compile-time vs run-time it makes no difference. The point is that Javascript silently hums along with no warning or error at all when you try to do something that many languages would not allow you to do without at least a warning. You can dig down into a semantic rabbit hole about what "throw" really means but I think you understand what I'm talking about.