Skip to main content
Commonmark migration
Source Link

#NULL is Overloaded.

NULL is Overloaded.

NULL simultaneously means:

  • This variable has not been initialised
  • This variable has been initialised, but does not point to a valid object, and as such is invalid
  • This variable has been initialised, but does not point to a valid object, and this is perfectly valid
  • This variable has been cleared and should never be used again
  • This is the magic third logic value

I'm quite likely missing a few definitions.

So which meaning does this NULL represent?

#The Solution

The Solution

Well that depends on the meaning being ascribed to NULL.

Optional works in the sense of knowing the state of initialisation, and that not being initialised is valid.

A NullObject works in that it conforms to an interface a can be used anywhere the normal object can be while doing some sort of default "nullish" behaviour.

A Trinary Logic Value works best when NULL is the third wheel in a logic system.

There are other solutions, but there isn't any reason to favour one solution over another across the board.

#Language Support

Language Support

At this level it boils down to how the type system is formulated.

Some systems prefer to have some relatively complex primitives. Usually these primitives are reflections of either an historical implementation, or of some underlying platform constraint. In the case of C# it inherited much of is syntax and semantic style from C/C++/Java. This is reflected in the fact that all object references are default nullable, and all values are default non-nullable.

In the case of C# the language, the type system is sufficiently complex to support an Optional type allowing value types to gain a nullable state, but there isn't a trivial way to remove nullability from the object references.

Some systems prefer to have very simple primitive types, and rely on a powerful type composition system to create the desired behaviours. In these languages a C# nullable Reference might look like def cs_reference(T) => NULL | T. The Optional pattern makes more sense though in these languages: def Option(T) => T[0..1]. Its an array/list/sequence of 0 or 1 element.

Using a sequence/array concept leverages our understanding of empty, and has one element. Its directly compatible with anything that accepts the sequence/array concept. And its recomposable within the type system T[0..1][0..1]. Where as cs_reference isn't cs_reference(cs_reference(T)) == NULL | T.

#NULL is Overloaded.

NULL simultaneously means:

  • This variable has not been initialised
  • This variable has been initialised, but does not point to a valid object, and as such is invalid
  • This variable has been initialised, but does not point to a valid object, and this is perfectly valid
  • This variable has been cleared and should never be used again
  • This is the magic third logic value

I'm quite likely missing a few definitions.

So which meaning does this NULL represent?

#The Solution

Well that depends on the meaning being ascribed to NULL.

Optional works in the sense of knowing the state of initialisation, and that not being initialised is valid.

A NullObject works in that it conforms to an interface a can be used anywhere the normal object can be while doing some sort of default "nullish" behaviour.

A Trinary Logic Value works best when NULL is the third wheel in a logic system.

There are other solutions, but there isn't any reason to favour one solution over another across the board.

#Language Support

At this level it boils down to how the type system is formulated.

Some systems prefer to have some relatively complex primitives. Usually these primitives are reflections of either an historical implementation, or of some underlying platform constraint. In the case of C# it inherited much of is syntax and semantic style from C/C++/Java. This is reflected in the fact that all object references are default nullable, and all values are default non-nullable.

In the case of C# the language, the type system is sufficiently complex to support an Optional type allowing value types to gain a nullable state, but there isn't a trivial way to remove nullability from the object references.

Some systems prefer to have very simple primitive types, and rely on a powerful type composition system to create the desired behaviours. In these languages a C# nullable Reference might look like def cs_reference(T) => NULL | T. The Optional pattern makes more sense though in these languages: def Option(T) => T[0..1]. Its an array/list/sequence of 0 or 1 element.

Using a sequence/array concept leverages our understanding of empty, and has one element. Its directly compatible with anything that accepts the sequence/array concept. And its recomposable within the type system T[0..1][0..1]. Where as cs_reference isn't cs_reference(cs_reference(T)) == NULL | T.

NULL is Overloaded.

NULL simultaneously means:

  • This variable has not been initialised
  • This variable has been initialised, but does not point to a valid object, and as such is invalid
  • This variable has been initialised, but does not point to a valid object, and this is perfectly valid
  • This variable has been cleared and should never be used again
  • This is the magic third logic value

I'm quite likely missing a few definitions.

So which meaning does this NULL represent?

The Solution

Well that depends on the meaning being ascribed to NULL.

Optional works in the sense of knowing the state of initialisation, and that not being initialised is valid.

A NullObject works in that it conforms to an interface a can be used anywhere the normal object can be while doing some sort of default "nullish" behaviour.

A Trinary Logic Value works best when NULL is the third wheel in a logic system.

There are other solutions, but there isn't any reason to favour one solution over another across the board.

Language Support

At this level it boils down to how the type system is formulated.

Some systems prefer to have some relatively complex primitives. Usually these primitives are reflections of either an historical implementation, or of some underlying platform constraint. In the case of C# it inherited much of is syntax and semantic style from C/C++/Java. This is reflected in the fact that all object references are default nullable, and all values are default non-nullable.

In the case of C# the language, the type system is sufficiently complex to support an Optional type allowing value types to gain a nullable state, but there isn't a trivial way to remove nullability from the object references.

Some systems prefer to have very simple primitive types, and rely on a powerful type composition system to create the desired behaviours. In these languages a C# nullable Reference might look like def cs_reference(T) => NULL | T. The Optional pattern makes more sense though in these languages: def Option(T) => T[0..1]. Its an array/list/sequence of 0 or 1 element.

Using a sequence/array concept leverages our understanding of empty, and has one element. Its directly compatible with anything that accepts the sequence/array concept. And its recomposable within the type system T[0..1][0..1]. Where as cs_reference isn't cs_reference(cs_reference(T)) == NULL | T.

Source Link
Kain0_0
  • 16.3k
  • 19
  • 40

#NULL is Overloaded.

NULL simultaneously means:

  • This variable has not been initialised
  • This variable has been initialised, but does not point to a valid object, and as such is invalid
  • This variable has been initialised, but does not point to a valid object, and this is perfectly valid
  • This variable has been cleared and should never be used again
  • This is the magic third logic value

I'm quite likely missing a few definitions.

So which meaning does this NULL represent?

#The Solution

Well that depends on the meaning being ascribed to NULL.

Optional works in the sense of knowing the state of initialisation, and that not being initialised is valid.

A NullObject works in that it conforms to an interface a can be used anywhere the normal object can be while doing some sort of default "nullish" behaviour.

A Trinary Logic Value works best when NULL is the third wheel in a logic system.

There are other solutions, but there isn't any reason to favour one solution over another across the board.

#Language Support

At this level it boils down to how the type system is formulated.

Some systems prefer to have some relatively complex primitives. Usually these primitives are reflections of either an historical implementation, or of some underlying platform constraint. In the case of C# it inherited much of is syntax and semantic style from C/C++/Java. This is reflected in the fact that all object references are default nullable, and all values are default non-nullable.

In the case of C# the language, the type system is sufficiently complex to support an Optional type allowing value types to gain a nullable state, but there isn't a trivial way to remove nullability from the object references.

Some systems prefer to have very simple primitive types, and rely on a powerful type composition system to create the desired behaviours. In these languages a C# nullable Reference might look like def cs_reference(T) => NULL | T. The Optional pattern makes more sense though in these languages: def Option(T) => T[0..1]. Its an array/list/sequence of 0 or 1 element.

Using a sequence/array concept leverages our understanding of empty, and has one element. Its directly compatible with anything that accepts the sequence/array concept. And its recomposable within the type system T[0..1][0..1]. Where as cs_reference isn't cs_reference(cs_reference(T)) == NULL | T.