Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

12
  • 5
    The problem is that there's no way to distinguish variables which should never contain null from those that should. For example, if I want a new type that contains 5 values in Java, I could use an enum, but what I get is a type that can hold 6 values (the 5 I wanted + null). It's a flaw in the type system. Commented May 2, 2014 at 17:51
  • @Doval If that is the situation just assign NULL a meaning (or if you have a default, treat it as a synonym of the default value) or use the NULL (which never should appear in the first place) as a marker of soft error (i.e. error but at least not crashing just yet) Commented May 2, 2014 at 17:59
  • 1
    @MaxtonChan Null can only be assigned a meaning when the values of a type carry no data (e.g. enum values). As soon as your values are anything more complicated (e.g. a struct), null can't be assigned a meaning that makes sense for that type. There is no way to use a null as a struct or a list. And, again, the problem with using null as an error signal is that we can't tell what might return null or accept null. Any variable in your program could be null unless you're extremely meticulous to check every single one for null before every single use, which no one does. Commented May 2, 2014 at 18:06
  • 1
    @Doval: There would be no particular inherent difficulty in having an immutable reference type regard null as a usable default value (e.g. have the default value of string behave as an empty string, the way it did under the preceding Common Object Model). All that would have been necessary would have been for languages to use call rather than callvirt when invoking non-virtual members. Commented May 3, 2014 at 15:58
  • @supercat That's a good point, but now don't you need to add support for distinguishing between immutable and non-immutable types? I'm not sure how trivial that is to add to a language. Commented May 3, 2014 at 16:04