Hacker News .hnnew | past | comments | ask | show | jobs | submitlogin

People aren't mad that errors aren't fixed automatically, people are mad that the behavior is inconsistent and weird for no fundamental reason other than "that's how the interpreter worked when it all started and it's too late to fix the spec now".

Python is a dynamic language as well and in many ways worse than JS, but

  [] + {}
raises a type error.

In JS

  [] + {}
is an object and

  {} + []
is 0. It's not about being smug, it's that in no way, shape or form that makes any sense.


First, [] + {} isn't an object, it's a string.

Second, {} + [] isn't a type conversion issue, it's a parsing issue. That {} isn't an object, it's a code block. Assign {} to a variable to ensure it's an object, then do var + [] and you get the same result as the first one.

When using an actual object in both of these, the type conversion makes sense: "+" acts on primitives like strings and numbers, so it has to convert them first. You're getting obj.toString() + array.toString() in either case.

I'll admit the parsing issue here is odd, but most of the time peoples' complaints about javascript type coercion is that they simply never bothered to learn how it works.


One can know the intricacies of how something works and still possess a valid opinion that it doesn't work all that well or defies common sense and expectations.


For me the difference is that you wouldn't then feel compelled to cynically bemoan it for retweets but this schtick went on for years where people would do something out of spec and then complain it was really bizarre to me! Anyway ... Being discouraged by a bug is fine... Making everyone else laugh at the machine on your behalf seems to against understanding and knowledge even if it is fun and funny haha


It’s absurd. Comedy is cognitive dissonance manifest. It can’t not be funny.


I don't have dissonance. The language has the features that were designed or there is a bug in what they intended and I don't know why you think adding two empty objects together should make sense anyway. That it doesn't work resolves the dissonance.


The complaint is that type coercion exists at all. It solves no problems and creates several out of thin air.

Or are you arguing that ceteris paribus you'd rather not have the language throw an error or just propagate undefined?


In the context of the time it was created it was fine to mess with and having an enlightened view from the future can't negate that even though I understand the complaint.


JS has had how many breaking changes since then...? They've transitioned to the future.

Why is it still here today?


> JS has had how many breaking changes since then...?

What breaking changes has JS ever had? Its an incredibly stable language.


Ok, lets reword that. JS has breaking changes in browsers or node at least once a year.

If the platform can continuously shift, in an ecosystem that rots faster than my veggie garden, can we not have more sensible systems in place?


You’ve still failed to give any examples of these breaking changes. Old websites still work great.

I’ll try again. What breaking changes does JavaScript make? What are you talking about?


8 months ago, Chrome rewrote how URLs work [0]. Which, unsurprisingly, affects the `URL` constructor in JS.

We have had so many APIs vanish from any context to "secure contexts" only. Like AppCache, or workers, or the clipboard.

Entire APIs like XMLHttpRequestProgressEvent have vanished entirely.

In fact, there is a lot of obsolete features. Enough that there's a list. [1] You can't use global or source with a RegExp anymore. You can't use the arity property on a function anymore. `Object.prototype.eval` is dead. `Object.getNotifier` is dead. `Date.prototype.toLocaleFormat()` is dead.

Old websites have been broken. Repeatedly. Or we wouldn't have, say, blogspam on why mixed content suddenly broke some Wordpress systems.

Yes, these are good changes. They're more secure. However, we're willing to break some sites in the name of security, but unwilling to fix ambiguous parsing for the programmer?

[0] https://hackernews.hn/item?id=41912354

[1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...


> peoples' complaints about javascript type coercion is that they simply never bothered to learn how it works

soo.... if the pesky people keep complaining, maybe it really doesn't make any sense? i for the life of me could never figure out why a bunch of mainstream languages a couple of decades ago decided that typing is no longer necessary and should be abolished. Is there any benefit of removing type checking (and relying on bizarre implicit coercion rules when ambiguity ensues)?


You will never bother me to learn something as convoluted as {} being sometimes parsed as an object and sometimes as a code block.


Thanks for posting this. People still don't seem to get that there's no mystery out to make their life difficult and that unfortunately everything can probably ultimately be understood in a deterministic system.


I've read your comment several times and I still don't get how I'm supposed to be frustrated by this?




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: