3 ms·
As long as you're stuck with null and undefined, you might as well throw in never for $3 billion! "My favorite is always the billion dollar mistake of having n
by DonHopkins 5y ago
As long as you're stuck with null and undefined, you might as well throw in never for $3 billion!
"My favorite is always the billion dollar mistake of having null in the language. And since JavaScript has both null and undefined, it's the two billion dollar mistake." -Anders Hejlsberg
"It is by far the most problematic part of language design. And it's a single value that -- ha ha ha ha -- that if only that wasn't there, imagine all the problems we wouldn't have, right? If type systems were designed that way. And some type systems are, and some type systems are getting there, but boy, trying to retrofit that on top of a type system that has null in the first place is quite an undertaking." -Anders Hejlsberg
- hajile 5y agoBut it's worse that that. var foo = new Array(5) That code will make an array with 5 elements, but their values aren't actually null or undefined, but another kind of "empty" value. You can't access this value directly (it will convert to undefined), but it still exists. EDIT: there's another kind of undefined that happens within the Temporal Dead Zone too
- nybble41 5y agoThis `never` type is the opposite of a null value, though. The "billion dollar mistake" (which is really the absence of non-nullable references, not merely the presence of null or undefined) adds a possible value to every reference. At any point you could have a valid reference, or a null reference, and this makes it impossible to express the type of a reference which must be valid. The `never` type by contrast has no possible values. It offers a way to statically assert that nothing has been left unhandled. A type system without `never` (or equivalent) is like a number system without zero. (Literally—`never` is the zero for algebraic data types.)