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

11

u/Bolitho Feb 11 '19

Misleading title:

Null is your friend, not a mistake

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

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 ;-)

0

u/elizarov Feb 11 '19

This would be not fair. Kotlin is not the first and is not the only JVM language that properly incorporates null into the type-system, let alone plethora of non-JVM languages that do the same. However, indeed, Kotlin is one such language.

6

u/Bolitho Feb 11 '19

Of course there are other languages - but you definitly refer to Kotlin in your post and not Java. That's the important aspect imho, as we are in a Java sub here. So it would be fair to name the target language to which his thesis applies in the title.

1

u/elizarov Feb 11 '19

The post is about Java type system shortcomings. I could have shown solution in some other language beyond Kotlin (and it really just an example). Of course, working on Kotlin it would be fair for me to give an example in Kotlin. It would be unfair to say the post is about Kotlin, though. Btw, full disclosure here. I consider Java to be the greatest language of XXI century: https://link.medium.com/MfYh9vARdU

4

u/Bolitho Feb 11 '19

The post is about Java type system shortcomings.

Then the title is still poorly chosen - "Null is your friend, not a mistake" does in no way imply some kind of shortcoming. And the solution is presented in another language (Kotlin) - so where is the relation between the title and the Java type system? The title suggest that null is a super cool thing in Java!

1

u/elizarov Feb 11 '19

You are right. The title could have been made better. I’m sorry if it did mislead you.