Void safety explained

Void safety (also known as null safety) is a guarantee within an object-oriented programming language that no object references will have null or void values.

In object-oriented languages, access to objects is achieved through references (or, equivalently, pointers). A typical call is of the form:

x.f(a, ...)

where f denotes an operation and x denotes a reference to some object. At execution time, however, a reference can be void (or null). In such cases, the call above will be a void call, leading to a run-time exception, often resulting in abnormal termination of the program.

Void safety is a static (compile-time) guarantee that a void call will never arise.

History

In a 2009 talk, Tony Hoare traced the invention of the null pointer to his design of the ALGOL W language and called it a "mistake":

Bertrand Meyer introduced the term "void safety".[1]

In programming languages

An early attempt to guarantee void safety was the design of the Self programming language.

The Eiffel language is void-safe according to its ISO-ECMA standard; the void-safety mechanism is implemented in EiffelStudio starting with version 6.1 and using a modern syntax starting with version 6.4.

The Spec# language, a research language from Microsoft Research, has a notion of "non-nullable type" addressing void safety.The F# language, a functional-first language from Microsoft Research running on .NET framework, is void-safe except when interoperating with other .NET languages.[2]

Null safety based in union types

Since 2011 several languages support union types and intersection types, which can be used to detect possible null pointers at compiling time, using a special class Null of which the value null is its unique instance.

The null safety based in types appeared first in the Ceylon, followed soon by TypeScript.

The C# language implements compile-time null safety check since version 8. However, to stay compatible with older versions of the language, the feature is opt-in on a per project or per file basis.[3]

Notes and References

  1. Bertrand Meyer: Attached Types and their Application to Three Open Problems of Object-Oriented Programming, in ECOOP 2005 (Proceedings of European Conference on Object-Oriented Programming, Edinburgh, 25–29 July 2005), ed. Andrew Black, Lecture Notes in Computer Science 3586, Springer Verlag, 2005, pages 1-32, also available online
  2. Web site: Syme . Don . Quote of the Week: "What can C# do that F# cannot?" . 7 September 2018.
  3. Web site: Announcing Dart 2 Stable and the Dart Web Platform. Moore. Kevin. 2018-08-07. Dart. 2018-08-08.
  4. Web site: Sound null safety . 12 March 2021.
  5. Web site: Null safety—Kotlin . 12 March 2021.
  6. Web site: Defining an Enum - The Rust Programming Language. 2021-06-26. doc.rust-lang.org.
  7. Web site: Nullable reference types | Microsoft Docs |url=https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references |accessdate=12 March 2021}}

    The Google's Dart language implements it since its version 2.0, in August 2018[3] [4]

    Other languages that use null-safe types by default include JetBrains' Kotlin,[5] Rust,[6] and Apple's Swift.

    See also

    References

    }

    .