4 ms·
The date on the article is April 2nd. I did check. Is the inclusion of this monstrosity in a standard library more evidence that null references are a misfeatu
by bensummers 17y ago
The date on the article is April 2nd. I did check.
Is the inclusion of this monstrosity in a standard library more evidence that null references are a misfeature? A explicit construction like Maybe<T> seems so much of a better idea.
- brown9-2 17y agowhy is this a monstrosity?
- bensummers 17y agoIt's a monstrosity because the underlying language design makes it necessary. A whole class of bugs could be eliminated if the language didn't allow you to have null references, and instead, made you explicitly state your function might not return an object, for example, the Maybe datatype in Haskell.
- samdk 17y agoYou can argue that null references are problematic and I'll agree with you. But they're a part of Java (and a whole host of other languages, too) and that's not going to change anytime soon. Saying that this is "a monstrosity" because nulls shouldn't exist in the first place is completely unhelpful. Whether we like them or not, we're going to be stuck with them for a long while, and attempts to make them less painful to deal with aren't a bad thing.
- jrockway 17y agoI'm not stuck with them, I just use Haskell. Just because Java is popular doesn't mean you have to use it.
- bensummers 17y agoExamining existing languages is useful to advance the art in computer language design. Being "stuck with them" just means we have the experience of writing software with these features. In addition, there's no reason we can't write a language without nulls which works on the JVM.
- samdk 17y agoBut we're not talking about advancing language design--we're talking about a small modification to an existing, widely used language whose basics are not going to change. There are a lot of problems with Java I'd like to see fixed before null, and the Java community has dismissed most of those as too radical (like closures). There are languages which work (mostly) without nulls on the JVM though. Scala does something very similar to Haskell's Maybe. (Although for interoperability with Java it can deal with nulls if you insist.)
- jrockway 17y agoThe power of Maybe in Haskell comes from both the existence of the type, and from the existence of sequencing combinators that understand how to handle Maybe. Just adding a Maybe type to Java wouldn't do anything; each method would still have to handle the Nothing case in some way. For Maybe to be useful in Java, control flow would have to change from running one line after another to "running" by applying functions, so that whether or not to run each "line of code" would be determined by a combinator that understands the semantics of Maybe. Then, of course, you just have Haskell, which already exists! A better option for Java would be a type that could not be null. I don't think the language allows the compiler to determine this, though, which means it probably won't exist (or if it does exist, it won't be too useful). Basically, if you want a good type system, you want to ditch Java.