Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, this is valid in languages with nullable types:

String s = null;

But this is not legal in languages without them:

String s = None;

In those languages, in order to have a value of None, it must be of type Option<String> (or whatever the syntax is), and in order to get a value of type String, you must assert its presence.

This is a fundamental difference with many ramifications. It really isn't just "the same but with better compile support".



    String s = null;
That's not possible with nullable types. The whole point of nullable types is to mark types that can be null. So this is possible:

    String? s = null;
But now it's not much different than this:

    Option<String> s = None;
My point is that these are fundamentally the same thing. The only difference is syntax, ergonomics, and compiler support.


That is legal in languages with poor null support. That statement would not be valid in Kotlin for example.


    String s = null;
This is a compile error in Dart now. We added nullable types in order to make all other types not nullable. So unless you explicitly opt in to nullability by putting "?" on the type, you can a type that does not permit null.


> No, this is valid in languages with nullable types:

> String s = null;

Only in languages with default-nullable types, (where the non-nullable form, if it exists at all, would be something like “String s!”); in languages with explicity billable types, the above is not allowed, because you would need to explictly opt-in to nullability:

  String s? = null




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: