On checking for existence: correct, but Guava's Optional has nice methods that allow you to easily check or set defaults etc. Can't get around that.
On still passing nulls through: The assumption is that you wouldn't be passing nulls around, and null passed as a parameter to a method would be an error, and warrants a NPE. You're not going to check for nulls on every method call even if you're not using Optional. This is no different. What do you get when using Optional: - syntax that explicitly identifies when a value is optional and a requirement to check if something exists before it gets used rather than hoping people know something maybe passed as null and requires checking before being used - less room for forgetting to do a null check, less room for guessing if a method accepts or returns nulls Comparison vs method overloading: - if you have many arguments that may be optional overloading can be a real pain. Are you going to create a method for every combo of arguments? - if you have a few arguments that are the same type, overloading won't work - you still have to tell the one method that accepts all the arguments that some of them are not set. Are you going to pass nulls? Is that method going to be public? Are callers of this method going to be passing nulls too? What have you solved then? Comparison vs builders: Sure, if an object is immutable, builders are better. But often, we're not constructing immutable objects. On Thu, Oct 10, 2019 at 11:25 AM Dyana Rose <dyanar...@gmail.com> wrote: > Optional doesn't get you out of null checks when you accept them as > parameters though, does it? the logic to determine if something is or isn't > there still has to be written if you have conditional logic based on the > existance or non-existance of the value. If an Optional is still a > reference type, you should still be able to send null through as a value as > well, unless there's a compile time restriction and the compiler can always > determine that a particular reference cannot be null. > > What do Optional parameters give you vs method overloading or a builder > pattern where you seed the required values via the initial builder > constructor. > > Dyana > > On 2019/10/09 19:46:42, Jad Naous <jad.na...@imply.io> wrote: > > Sir Tony Hoare on inventing null while working on ALGOL (from wikipedia > > below): > > > > Speaking at a software conference called QCon London > > <https://qconlondon.com/> in 2009, he apologised for inventing the null > > reference <https://en.wikipedia.org/wiki/Null_pointer>:[23] > > <https://en.wikipedia.org/wiki/Tony_Hoare#cite_note-23> > > > > I call it my billion-dollar mistake. It was the invention of the null > > reference in 1965. At that time, I was designing the first comprehensive > > type system for references in an object oriented language (ALGOL W > > <https://en.wikipedia.org/wiki/ALGOL_W>). My goal was to ensure that all > > use of references should be absolutely safe, with checking performed > > automatically by the compiler. But I couldn't resist the temptation to > put > > in a null reference, simply because it was so easy to implement. This has > > led to innumerable errors, vulnerabilities, and system crashes, which > have > > probably caused a billion dollars of pain and damage in the last forty > > years. > > > > How about we stop passing nulls around as method arguments, field values, > > return values, etc and use Optional instead? Benefits: > > - No more NPEs > > - Better documentation through code > > - Less mistakes > > > > I'm not suggesting we go rewrite everything, but rather just starting to > > only return and accept Optionals in methods/constructors/etc. > > > > Jad. > > > > -- > > Jad Naous > > Imply | VP R&D > > 650-521-3425 > > jad.na...@imply.io > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: dev-unsubscr...@druid.apache.org > For additional commands, e-mail: dev-h...@druid.apache.org > > -- Jad Naous Imply | VP R&D 650-521-3425 jad.na...@imply.io