Live data from Hacker News

Retrofitting null-safety onto Java at Meta

engineering.fb.com

21–30 of 230 posts

Re: Retrofitting null-safety onto Java at Meta

#21
It's so sad that Java 8 had the chance to really fix the null problem, but gave us only the half-assed `java.util.Optional`. Rather than implementing optional values at the language level, it's just another class tossed into the JRE.

This is perfectly legal code, where the optional wrapper itself is null:

    Optional getMiddleName() {
        return null;
    }

Re: Retrofitting null-safety onto Java at Meta

#22

Earlier quoted context omitted.

I can't think of any popular language that would take more than a few days to get acclimated to as an experienced developer, so that's not a very compelling argument.

Well, C and Scala are some counter examples that immediately come to mind. Kotlin is probably more similar to Java than any other mainstream language. There’s almost no learning curve there, while going from Java to other “easy” languages like Python requires significantly more time to get used to.

Scala it depends how you want to use it. If you're going for full FP then sure it can take a little bit longer, but you can also just use it like Java+ if you really want...

Re: Retrofitting null-safety onto Java at Meta

#23

This is just covering up design problems. NPEs show you were you have design deficiencies. If you have getAccount().getContact().getPhoneNumber() and contact is null, you'll get an NPE. The question shouldn't be: "How do I shove the NPE under the rug for the next 1337 coder to deal with?", the question should be: "How did I initialize an Account without a Contact?"

Yes and Null safety forces you to ask that question at compile time instead of runtime

Re: Retrofitting null-safety onto Java at Meta

#24
post #21

It's so sad that Java 8 had the chance to really fix the null problem, but gave us only the half-assed `java.util.Optional `. Rather than implementing optional values at the language level, it's just another class tossed into the JRE. This is perfectly legal code, where the optional wrapper itself is null: Optional getMiddleName() { return null; }

Don't people use @NonNull everywhere now? It's been a few years since I've programmed in Java but even then I feel like that was common practice.

Re: Retrofitting null-safety onto Java at Meta

#25

This is just covering up design problems. NPEs show you were you have design deficiencies. If you have getAccount().getContact().getPhoneNumber() and contact is null, you'll get an NPE. The question shouldn't be: "How do I shove the NPE under the rug for the next 1337 coder to deal with?", the question should be: "How did I initialize an Account without a Contact?"

> the question should be: "How did I initialize an Account without a Contact?"

Well yeah that's exactly what static analysis can tell you - what code path led to that.

You're saying this project should be what it already is.

Re: Retrofitting null-safety onto Java at Meta

#26

Or use Kotlin, it's near perfectly interoperable with Java and the acclamation period is measured in weeks if you're a Java dev

I can't think of any popular language that would take more than a few days to get acclimated to as an experienced developer, so that's not a very compelling argument.

Rust can take a while if you don't know either C++ or Haskell.

Re: Retrofitting null-safety onto Java at Meta

#27

This is just covering up design problems. NPEs show you were you have design deficiencies. If you have getAccount().getContact().getPhoneNumber() and contact is null, you'll get an NPE. The question shouldn't be: "How do I shove the NPE under the rug for the next 1337 coder to deal with?", the question should be: "How did I initialize an Account without a Contact?"

> This is just covering up design problems.

Static analysis (detecting) is the opposite of "covering up".

> "How did I initialize an Account without a Contact?"

As long as your language lets you do it, your teammates will do it. And in many cases it won't be accidental either. Your teammate will want an Account with its Contact set to null.

Re: Retrofitting null-safety onto Java at Meta

#28
post #21

It's so sad that Java 8 had the chance to really fix the null problem, but gave us only the half-assed `java.util.Optional `. Rather than implementing optional values at the language level, it's just another class tossed into the JRE. This is perfectly legal code, where the optional wrapper itself is null: Optional getMiddleName() { return null; }

It may have been hoped for, but it was an unrealistic hope.

They couldn't have fixed it while retaining backward compatibility.

Re: Retrofitting null-safety onto Java at Meta

#29
post #21

It's so sad that Java 8 had the chance to really fix the null problem, but gave us only the half-assed `java.util.Optional `. Rather than implementing optional values at the language level, it's just another class tossed into the JRE. This is perfectly legal code, where the optional wrapper itself is null: Optional getMiddleName() { return null; }

Don't people use @NonNull everywhere now? It's been a few years since I've programmed in Java but even then I feel like that was common practice.

Seems common, though it only helps so much with 3rd party libraries.

Re: Retrofitting null-safety onto Java at Meta

#30
post #21

It's so sad that Java 8 had the chance to really fix the null problem, but gave us only the half-assed `java.util.Optional `. Rather than implementing optional values at the language level, it's just another class tossed into the JRE. This is perfectly legal code, where the optional wrapper itself is null: Optional getMiddleName() { return null; }

I love this solution. Now you have two kinds of nulls.
Post reply on HN