Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by bogomipz on Monday May 30, 2016 @10:13AM
(#11801427)
I have a question about null being able to subvert types, using Java an example, if I write foo.upperCase() and foo is a string, the type check succeeds but will produce an NPE at runtime. Why doesn't javac catch that foo is not set i.e is "null." Why is null above type checks?
[ Parent
| on HN ]
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by zaphar on Monday May 30, 2016 @10:28AM
(#11801487)
Because whether foo's value is null is for most cases only detectable at runtime precisely because java doesn't have the capability to express disjoint type sets in it's type system the way that say Haskell or F# do. This inability means that the programmer can't tell the compiler what code paths produce null vs what code paths produce string. As a result the compiler has to assume that all codepaths could produce both.
There are some trivial cases where the compiler could figure it out for you but most of those cases are not very useful in practice.
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by bogomipz on Monday May 30, 2016 @11:14AM
(#11801664)
Interesting, is there a formal name for this kind of type system that has the ability to look at the code paths and express disjoint type sets?
Is this a trend in newer languages in general or an FP specific thing?
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by zaphar on Monday May 30, 2016 @09:44PM
(#11804122)
Typically it's referred to as an Algebraic Data Type https://en.wikipedia.org/wiki/Algebraic_data_type. Any Type System that can express this type will be able to do the above.
It's not necessarily new since the ML family of languages has had it for a while now. It's also not limited to FP languages but it best known from ML the ML family. Rust has it though as well as Swift i think.
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by bogomipz on Wednesday June 01, 2016 @10:41AM
(#11814674)
I see. Thank you for the follow up. This is really helpful. Haskell implements this data type which is why it has come up in this discussion. I need to spend some time with something from the ML family.
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by airless_bar on Monday May 30, 2016 @01:12PM
(#11802165)
> formal name
non-shitty
> a trend in newer languages
yes, only discovered a few decades ago
:-D
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by bogomipz on Monday May 30, 2016 @02:01PM
(#11802355)
I understand making a snarky comment in addition to some meaningful commentary but really two useless comments? Why even take the time to do so?
Re:Null References: The Billion Dollar Mistake – Tony Hoare ...
by airless_bar on Monday May 30, 2016 @05:41PM
(#11803378)
Sorry, was meant to be a light-hearted response.