HOME

TheInfoList



OR:

Void safety (also known as null safety) is a guarantee within an
object-oriented programming language Object-oriented programming (OOP) is a programming paradigm based on the concept of "objects", which can contain data and code. The data is in the form of fields (often known as attributes or ''properties''), and the code is in the form of ...
that no object references will have ''null'' or ''void'' values. In object-oriented languages, access to objects is achieved through
references Reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''name'' ...
(or, equivalently,
pointers Pointer may refer to: Places * Pointer, Kentucky * Pointers, New Jersey * Pointers Airport, Wasco County, Oregon, United States * The Pointers, a pair of rocks off Antarctica People with the name * Pointer (surname), a surname (including a l ...
). 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 An abnormal end or abend is an abnormal termination of software, or a program crash. This usage derives from an error message from the IBM OS/360, IBM zOS operating systems. Usually capitalized, but may appear as "abend". Some common ABEND codes ...
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 Sir Charles Antony Richard Hoare (Tony Hoare or C. A. R. Hoare) (born 11 January 1934) is a British computer scientist who has made foundational contributions to programming languages, algorithms, operating systems, formal verification, and c ...
traced the invention of the
null pointer In computing, a null pointer or null reference is a value saved for indicating that the pointer or reference does not refer to a valid object. Programs routinely use null pointers to represent conditions such as the end of a list of unknown lengt ...
to his design of the
ALGOL W ALGOL W is a programming language. It is based on a proposal for ALGOL X by Niklaus Wirth and Tony Hoare as a successor to ALGOL 60. ALGOL W is a relatively simple upgrade of the original ALGOL 60, adding string, bitstring, complex number and ...
language and called it a "mistake":
Bertrand Meyer Bertrand Meyer (; ; born 21 November 1950) is a French academic, author, and consultant in the field of computer languages. He created the Eiffel programming language and the idea of design by contract. Education and academic career Meyer recei ...
introduced the term "void safety".


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 ISO is the most common abbreviation for the International Organization for Standardization. ISO or Iso may also refer to: Business and finance * Iso (supermarket), a chain of Danish supermarkets incorporated into the SuperBest chain in 2007 * Iso ...
- ECMA standard; the void-safety mechanism is implemented in
EiffelStudio EiffelStudio is a development environment for the Eiffel programming language developed and distributed by Eiffel Software. EiffelStudio includes a combination of tools integrated under a single user interface: compiler, interpreter, debugger, bro ...
starting wit
version 6.1
and using a modern syntax starting wit
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.


Null safety based in union types

Since 2011 several languages support
union type In computer science, a union is a value that may have any of several representations or formats within the same position in memory; that consists of a variable that may hold such a data structure. Some programming languages support special data ...
s and
intersection type In type theory, an intersection type can be allocated to values that can be assigned both the type \sigma and the type \tau. This value can be given the intersection type \sigma \cap \tau in an intersection type system. Generally, if the ranges o ...
s, 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 Sri Lanka (, ; si, ශ්‍රී ලංකා, Śrī Laṅkā, translit-std=ISO (); ta, இலங்கை, Ilaṅkai, translit-std=ISO ()), formerly known as Ceylon and officially the Democratic Socialist Republic of Sri Lanka, is an ...
, followed soon by
TypeScript TypeScript is a free and open source programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are ...
. The C# language implements compile-time null safety check since version 8. However, to stay compatible with anterior versions of the language, the feature is opt-in on a per project or per file basis. The Google's
Dart Dart or DART may refer to: * Dart, the equipment in the game of darts Arts, entertainment and media * Dart (comics), an Image Comics superhero * Dart, a character from ''G.I. Joe'' * Dart, a ''Thomas & Friends'' railway engine character * Dar ...
language implements it since its version 2.0, in August 2018 Other languages that use null-safe types by default include JetBrains' Kotlin,
Rust Rust is an iron oxide, a usually reddish-brown oxide formed by the reaction of iron and oxygen in the catalytic presence of water or air moisture. Rust consists of hydrous iron(III) oxides (Fe2O3·nH2O) and iron(III) oxide-hydroxide (FeO(OH ...
, and Apple's
Swift Swift or SWIFT most commonly refers to: * SWIFT, an international organization facilitating transactions between banks ** SWIFT code * Swift (programming language) * Swift (bird), a family of birds It may also refer to: Organizations * SWIFT, ...
.


See also

*
Nullable type Nullable types are a feature of some programming languages which allow a value to be set to the special value NULL instead of the usual possible values of the data type. In statically typed languages, a nullable type is an option type, while in ...
*
Option type In programming languages (especially functional programming languages) and type theory, an option type or maybe type is a polymorphic type that represents encapsulation of an optional value; e.g., it is used as the return type of functions whic ...
*
Safe navigation operator In object-oriented programming, the safe navigation operator (also known as optional chaining operator, safe call operator, null-conditional operator, null-propagation operator) is a binary operator that returns null if its first argument is null; ...


References

Object-oriented programming {{Comp-sci-stub