News for hackers. Stuff that matters.
Re:Deprecating: java.util.Optional.get()? by weego on Thursday April 28, 2016 @10:51AM (#11589274)
You should never have concrete expectations or make assertions on an unknown, that's the entire point of any implementation of Option.

Option.get leads to false confidence. I've had many arguments over use .get (in Scala) where another developers argument is "we check that it's defined higher up in the code". At that point a harmless looking refactor by someone else can introduce NPEs.

Re:Deprecating: java.util.Optional.get()? by masklinn on Thursday April 28, 2016 @11:03AM (#11589365)
> You should never have concrete expectations or make assertions on an unknown

As long as Optional#isPresent exists, you can have "concrete expectations" of an optional's content (or lack thereof).

> At that point a harmless looking refactor by someone else can introduce NPEs.

The fundamental problem is not .get, it's that you're qualifying code changes involving partial function as "harmless-looking" and "refactoring"

Re:Deprecating: java.util.Optional.get()? by pcwalton on Thursday April 28, 2016 @01:08PM (#11590353)
Option.get is important. It lets you work around the type system in cases where the type system wasn't expressive enough. Given that all type systems are imprecise, this functionality is essential.

I'm all for strong type systems, but I also acknowledge their limitations.

Re:Deprecating: java.util.Optional.get()? by gozur88 on Thursday April 28, 2016 @02:29PM (#11590939)
If someone has managed to bork the code with a harmless looking refactor, an NPE is what you want. The code is no longer working as designed and needs to be fixed.
Re:Deprecating: java.util.Optional.get()? by matt_kantor on Friday April 29, 2016 @03:20AM (#11594246)
Remember that in this scenario the alternative to an NPE is that the program doesn't even compile (because it won't type check).