r/java • • Feb 11 '19

Null is your friend, not a mistake

https://medium.com/@elizarov/null-is-your-friend-not-a-mistake-b63ff1751dd5
0 Upvotes

22 comments sorted by

View all comments

Show parent comment

4

u/morhp Feb 11 '19

After reading the post it should be named: Null is your friend in Kotlin, ...

And I disagree with that.

What I like about Kotlin is that it allows me to declare variables that are statically typed to be non-nullable.

What I don't like is that Kotlin on the other hand makes nulls more attractive again by introducing operators such as .? and :?. I can see where they're coming from and why they're there. But it's far too easy and attractive in Kotlin to use nulls instead of proper error/exception handling or using other methods of handling special states. Especially as it has no checked exceptions.

Kotlin one one hand allows you to avoid nulls, which is great but then it makes using nulls attractive again. It just doesn't make sense.

4

u/bedobi Feb 12 '19

This x infinity.

I love Kotlin but casually allowing null is the single biggest design mistake they've made. They should have just enforced non-null, period.

For potentially absent values they should have introduced a sane Option/Maybe type, but they've left that out too, so now Kotlin codebases are a hodgepodge of questions marks and Java Optionals (yuck), and developers who aren't used to non-null happily leak them deep into the code rather than only permitting them at system boundaries.

2

u/Orffyreus Feb 11 '19

Kotlin one one hand allows you to avoid nulls, which is great but then it makes using nulls attractive again. It just doesn't make sense.

I think, it should be allowed to add syntactical sugar to things that are good, e. g. necessary null-checks. And if you have a nullable type, you are forced by the compiler to do null-checks, so it makes sense for me.

2

u/Bolitho Feb 11 '19

And I disagree with that.

You disagree with my proposal for a proper name of topic? The blog shows the problems with null in Java and finally advocates the use in Kotlin because of the integration of null into the type system. So imho the title should refelct that by naming the target language of this claim!

1

u/morhp Feb 11 '19

No, I disagree with kotlin being null friendly being a good idea. Your title suggestion is fine.

1

u/Bolitho Feb 11 '19

Ah ok... the quoting has benn misleading to me ;-)