JavaScript
-
This post did not contain any content.
Oh we've hit an issue that's solved by another language or we could make another framework
-
Which "1" did it remove? And did it search the string to find a "1" to remove, or did it remove whichever character happened to be at array index 1?
maybe we removed the last n characters
-
This is too stupid so I had to check.
Fuck me.
pro tip:
"ba" + 0/0 + "a"
-
If you mix types like that, it's your own fault
BS. A language shouldn't have operators that allow non sensical operations like string concatenation when one operand is not a string.
-
it commutes
Maybe the behaviour with regard to type conversion, but not for the operation itself.
"13"+12 and 12+"13" don't yield the same result.
Nor would I expect "1312" to equal "1213".. Still that operator with these operands should just throw an exception
-
It is 'comprehensible' in the sense that it's possible to figure out how it happened, but it absolutely does not "make sense" in terms of being a reasonable language design decision. It's 100% incompetence on the part of the person who created Javascript.
Thanks for saving me the typing.
-
It was never intended to run full applications but only the small business scripts and hobbyist homepage stuff that were the thing in the 90s, across inconsistent browsers that were a jungle of hit and miss behaviour where it was preferred that menus keep working even if the mouse effect was not. Anything of scale was expected to be done in Java. Dynamic web pages did not exist and as anything not static was generated server side into a static html file to be rendered on the client.
Anyway, back then it wasn't considered the job of the programming language to hold the hand of the aspiring developer as it is common today. It's not a bad thing that IDE and even compilers and preprocessors try to help you write better code today, but then it simply didn't exist.
JavaScript is from a different time and because it has the hard requirement or backwards compatibility there is no changing it and has not been for thirty years except to add stuff to it.
I think it's just silly to ask the past to keep up with the present. Bad code is not the fault of the language regardless, even though junior devs and even seasoned ones like to think so to protect their ego. I think it is better to accept it, learn from it and roll with it because every single platform and language has their weird quirks anyway.
Signed, old dude that learned programming in 8 bit BASIC and 6502 machine code without an assembler, where code bad enough would freeze your machine that required a cold boot and starting over from your last save that you didn't do.
Executing after undefined behavior is arguably worse than terminating with an exception. A terminated script can't leak data or wreak havoc in other ways.
-
Nor would I expect "1312" to equal "1213".. Still that operator with these operands should just throw an exception
Given it's JavaScript, which was expressly designed to carry on regardless, I could see an argument for it returning NaN, (or silently doing what Perl does, like I mention in a different comment) but then there'd have to be an entirely different way of concatenating strings.
-
If you mix types like that, it's your own fault
Lol. In a dynamically typed language? I will do this always, that's why I am using it
-
pro tip:
"ba" + 0/0 + "a"
This has got to be baNaNa
-
wrote on last edited by [email protected]
Hear me out:
"11" - 1 = "11" - (-1) = "11" (did not find "-1" in "11)
Or
"11" - 1 = "11" - (-1) = "1" (removed first "1")
-
It's not that hard to understand what it is doing and why the decision was made to make it do that. JavaScript has a particular purpose and it's mission is not consistency.
It's not like TypeScript doesn't exist if you just get lightheaded at the idea of learning JavaScript's quirks and mastering using it despite them.
wrote on last edited by [email protected]Scanned the article: neither mission, nor purpose, nor type coercion unga-bunga explained. Or was I expected to see the greatness of the language and be humbled by its glory and might?
-
BS. A language shouldn't have operators that allow non sensical operations like string concatenation when one operand is not a string.
Especially that + and - act differently. If + does string concattenation, - should also do some string action or throw an error in this situation.
-
Especially that + and - act differently. If + does string concattenation, - should also do some string action or throw an error in this situation.
That's the case in many languages, pretty much in all that don't have a separate string concatenation operator.
-
Which "1" did it remove? And did it search the string to find a "1" to remove, or did it remove whichever character happened to be at array index 1?
It should just randomly pick any "1". Add a bit of spice, you know
-
Scanned the article: neither mission, nor purpose, nor type coercion unga-bunga explained. Or was I expected to see the greatness of the language and be humbled by its glory and might?
Well then, rage against the machine for the next 30 years and see if they kill it in favor of a nice, strict language that everybody loves. Maybe you could suggest one here for consideration.
-
Given it's JavaScript, which was expressly designed to carry on regardless, I could see an argument for it returning NaN, (or silently doing what Perl does, like I mention in a different comment) but then there'd have to be an entirely different way of concatenating strings.
Why would you need an entirely different way of concatenating strings? "11" + 1 -> exception. "11" + to_string(1) = "111"
-
Now that you mention it, it is a bit funny how Lemmy is hating LLMs as a code generation tool while also hating on the interpreter for their own hand typed code not running.
I mean, in both cases it's because the LLM and interpreter do things you wouldn't expect.
-
This post did not contain any content.wrote on last edited by [email protected]
This is my favorite language: GHC Haskell
GHC Haskell:
GHCi> length (2, "foo") 1
-
Especially that + and - act differently. If + does string concattenation, - should also do some string action or throw an error in this situation.
- should also do some string action
Like what kind of string action?
"Hello" + " world" is what everyone can understand. Switch with "-" and it becomes pointless.