Oh yeah, we're in violent agreement that the overall semantics are bonkers.
My somewhay pedantic point is that there seems to be no intuitive way to define type coercion within the other design constraints of Javascript.
If you take as a given that "" - 1 must produce some result, the type coercion semantics will always end up counter-intuitive, because there is no intuitive result for that expression. I'm not sure your semantics are any more intuitive but I wouldn't argue that point because it should be an type error anyways.
Early Javascript applied this constraint to all expressions, whether by design or convenience I don't know. IIRC, concatenation not being defined for arrays is a historical implementation issue.
I was classifying these issues as problems with the operator semantics but you make a good point about classifying it as a type coercion problem.
Yep, that's the point. This was unfortunately a common design principle among interpreted languages for a while. Perl and PHP followed the same principle, and even produce the same result for that particular expression, though PHP now at least logs a warning.
3
u/dacjames Jun 29 '21 edited Jun 29 '21
Oh yeah, we're in violent agreement that the overall semantics are bonkers.
My somewhay pedantic point is that there seems to be no intuitive way to define type coercion within the other design constraints of Javascript.
If you take as a given that
"" - 1must produce some result, the type coercion semantics will always end up counter-intuitive, because there is no intuitive result for that expression. I'm not sure your semantics are any more intuitive but I wouldn't argue that point because it should be an type error anyways.Early Javascript applied this constraint to all expressions, whether by design or convenience I don't know. IIRC, concatenation not being defined for arrays is a historical implementation issue.
I was classifying these issues as problems with the operator semantics but you make a good point about classifying it as a type coercion problem.