Imagine doing math with strings and then blaming the language not yourself
Programmer Humor
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
The risk is when it happens unintentionally. The language is bad for hiding such errors by being overly 'helpful' in assuming intent.
Sure, but at this point it's your own fault if you don't use Typescript to keep these issues from happening.
"Use a different language" is a common defense of javascript, but kind of a weird one.
Not really, considering Typescript only adds static types to JS. It's not a different language, it's an extension.
Since it needs to be compiled to JavaScript in order to be used, I kind of consider it a different language. Yes, it's a strict superset of JavaScript, but that makes it different.
So, just don’t use JavaScript?
That's also my understanding: "Javascript is great because you can use other languages and then transpile them to JS."
Oh man machine language is so good, literally the best actually
The problem is consistency.
To start off... Using arithmetic operators on strings in combination with integers is a pure skill issue. Let's disregard this.
If you were to use + where one part is a string, it's natural to assume a string appending is desired since + is commonly used as a function for this. On the other hand, - is never used for any string operation. Therefore, it's safe to assume that it relates to actual artihmetics and any strings should therefore be converted to numerical values.
This is an issue with untyped languages. If you don't like it, use typescript. End of story.
Instead of trying to make it work, javascript could just say "error." Being untyped doesn't mean you can't have error messages.
This is fair enough from an idealistic view. In practice, you don't want your entire website to shit itself because of a potentially insignificant error.
This is exactly why it should throw an error, to make it incredibly obvious something isn't working correctly so it can be fixed. Otherwise you have wrong logic leading to hard to notice and hard to debug problems in your code
I'd rather have my website shit itself than have silent difficult to find errors.
Look! I bought this for free on capybaras website, there's a glitch!
capybara: at least it didn't throw an error.
/ jk 😁
Javascript is a dogshit language that everyone is stuck with. The best that we can hope for is the likes of typescript take the edge off of it. Even though it's like smearing marzipan over a turd. At least it's ok if you don't take a deep bite.
JS should have never leaved the Browser side. Now you can use this thing for Backend and is just awful
That is just the tip of the iceberg:
Oh wow, that's upsetting
F#? What? We can't curse on the internet? Self censorship at dictator levels here. /s
so plus coerces into string if not number, was that so hard?
Heck, I need to learn some new languages apparently. Here I was expecting an angry "CS0029 cannot implicitly convert type 'string' to 'int'!
It makes sense though
This here is my absolute favorits way to diss someone. Send the a wikipeda link and bam!
.... It does?
It does to some degree.
- "11" is string, 1 is an int, because strings can be added (+) convert int to string and combine: "11"+"1" = "111"
- "11" is string, 1 is an int, because strings cant be subtracted (-) convert string to int and combine: 11-1 = 10
I'm not into JS so I don't know how it takes priority. ints can be added too, so I guess its basing it on the first variable which is compatible with the operator: in the first case string, in the second case int.
If this is how it works, it makes sense. But imo its a case of the designers being preoccupied with whether or not they could, they didn't stop to think if they should.
If you're consciously and intentionally using JavaScript like that, I don't want to be friends with you.
javascript is to web developers what powerpoint is to sales people