Live data from Hacker News

Java 8’s new Optional type doesn't solve anything

medium.com

191–197 of 197 posts

Re: Java 8’s new Optional type doesn't solve anything

#191
post #107
post #103

Earlier quoted context omitted.

It's a very simple question to answer: "return null" returns null.

then this abstraction has sprung a serious leak. the article seems to be fully right.

The point is that wherever that happens, it's an obvious flaw with the method returning the null, and can also be caught by static analysis. It means that in general, the problem is avoided.

Yes, it's not ideal, it's still a flaw that should be caught at compile-time, but it's not a big real-world problem, as returning null by accident instead of an option is a pretty rare bug.

The much more common bug (you didn't realize no return value was a case), the Option is a good counter to.

No, it's not a perfect solution, but it's not useless either.

Re: Java 8’s new Optional type doesn't solve anything

#192
post #191
post #107

Earlier quoted context omitted.

then this abstraction has sprung a serious leak. the article seems to be fully right.

The point is that wherever that happens, it's an obvious flaw with the method returning the null, and can also be caught by static analysis. It means that in general, the problem is avoided. Yes, it's not ideal, it's still a flaw that should be caught at compile-time, but it's not a big real-world problem, as returning null by accident instead of an option is a pretty rare bug. The much more common bug (you didn't re…

i understand, and agree. i would personally, though, avoid adding it, and add attributes for the same purpose instead. just as the article suggests... it achieves the same without introducing a new class, thus also remaining backwards compatible.

Re: Java 8’s new Optional type doesn't solve anything

#193
Where did this myth that Option types are the "solution" to nullable references come from? That's got it perfectly backwards. The solution to nullable references is to remove them from the language; Option is just a means for languages that have already done this to encode nullability into the type of a value add necessary, as it should be. And people claiming that a language needs pattern matching or it doesn't solve the problem?! It makes me worry that those advocating these ideas are just part of the latest cargo cult and don't really understand the underlying principles or why these are good ideas in the first place.

Re: Java 8’s new Optional type doesn't solve anything

#194
post #186

Earlier quoted context omitted.

Curious. Can you provide a full code example so that I can try to determine what's causing that error?

Usually in these cases the culprit is autoderef/deref coercions.

I don't see anything in `|x| foo(x)` that could be causing `x` to be deref'd.

Re: Java 8’s new Optional type doesn't solve anything

#195
post #186

Earlier quoted context omitted.

Curious. Can you provide a full code example so that I can try to determine what's causing that error?

Just make an issue?

I don't think it necessarily warrants an issue on the Rust repo, this is just for my own edification.

Re: Java 8’s new Optional type doesn't solve anything

#197
post #194

Earlier quoted context omitted.

Usually in these cases the culprit is autoderef/deref coercions.

I don't see anything in `|x| foo(x)` that could be causing `x` to be deref'd.

A deref coercion can happen there

https://github.com/Manishearth/rust-clippy/issues/116

Post reply on HN