Hacker News new | past | comments | ask | show | jobs | submit login

If we look at set theory the NULL set is a valid set. The problem with NULL is often it's just treated as zero or if passed to a language that does not have NULL it's pretty often to just treat it as Zero. This bit equivalence between zero and NULL zero is often what you see lead to problems.

It's why for instance with GPS coordinates NULL island exists.

However, errors aside NULL is a perfectly logical value to encounter or need.




> NULL is a perfectly logical value to encounter or need.

Great! Assign to it the type Null.

This is legal:

    Null myNull = null;
Make this illegal:

    Integer i = null;


This is essentially what Dart does:

https://api.dart.dev/stable/2.10.4/dart-core/Null-class.html

The main change with adding nullable and non-nullable types to the language is that we no longer treat Null as a subtype of all types. Instead, you have to opt in using "?", which is basically syntactic sugar for "| Null".


NULL can be its own type, but the union between the set of integers and NULL is equally valid. However, that new set created by this union is not just integers.

To represent a type that can be NULL or an integer it should be a different type.

Like I said the problem again is mostly your data is not always contained to your language. If you export GPS coordinates some systems may treat this composite type incorrectly. So even if you have a strong type system people will just be lazy.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: