if (foo.bar.length >= baz.buz) {
...
} otherwise {
// what am I supposed to do here?
}
How do I disambiguate if the "broken" type coercion was actually what I wanted? How do I tell what circumstances conspired to make this statement not-clearly-true?But in the absence of this information, my first guess would be:
if (foo.bar.length >= baz.buz) {
...
} otherwise {
alert("Something unexpected happened. Either foo.bar.length or baz.buz is not a number.")
}Isn't what you're describing here basically equivalent to saying JS should throw on invalid comparisons, with
try {if (x) then A else B} catch C
rewritten as if (x) then A else B otherwise C
?But WHY are you trying to compare them? The fact that one of these variables is a field called LENGTH is highly suggestive of some particular semantics that you intend these variables to have.
> there's a dozen different ways where that comparison could involve type coercion
That's right, which is the reason I can't answer your question as you posed it.
I predict that if you try to fill in the details what you will find is that you will be unable to do so in any way that does not reveal the presence of something badly wrong in your design.
> The "third boolean" value is useless unless you completely redesign the language.
You have to add an OTHERWISE clause to the IF statement and change the semantics of some operators. That's not a "complete redesign."
Interesting way of expressing the result of an ill-defined operation. Or am I off base?
Don't get me wrong - I don't know who you are but your username is in my mental bucket of "people worth paying attention to" just from past comments. I ask because the idea of a three-valued boolean seems rather more "magical" than whatever sins JS already commits by defining comparisons such that (a<=b || b<=a) can be false, and so on. I mean, isn't it a contradiction in terms to begin with, to call such a beast a boolean?