Nullable type
See also Null References - The Billion Dollar Mistake by Tony Hoare, Tony Hoare, Null (SQL), Null reference, Null pointer, Null pointer exception, Null-Safety
TLDR: A nullable type is a data type that explicitly allows the representation of null values, introduced to handle the absence of a value safely. This concept gained prominence with the introduction of nullable annotations in C Sharp 2.0 in 2005 and was later adopted by languages like Kotlin and Swift. Nullable types prevent runtime errors by enforcing null safety at the type level.
https://en.wikipedia.org/wiki/Nullable_type
In C Sharp, nullable types are denoted by a question mark (`?`) appended to the type, such as `int?`. This allows the variable to hold either a value or `null`. For example, `int? number = null;` is valid and avoids potential runtime exceptions. Similarly, Kotlin uses explicit nullable types with the syntax `Int?`, and the compiler enforces checks to ensure safe usage, such as requiring null checks before accessing properties or methods.
https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/nullable-types/
The introduction of nullable types significantly reduces null pointer exceptions, a common source of bugs in many programming languages. By explicitly distinguishing between nullable and non-nullable types, developers are encouraged to handle null values properly, either by providing default values or using safe call operators (`?.`) to prevent unsafe dereferencing.
https://kotlinlang.org/docs/null-safety.html
Adopting nullable types enhances code clarity and robustness, especially in large-scale projects. Tools like SonarQube and Pylint analyze code for nullability issues, helping teams maintain high-quality, error-free codebases. As more languages incorporate null safety into their core, nullable types have become a standard practice for reducing runtime errors and improving software reliability.
https://www.sonarsource.com/products/sonarqube/
- Snippet from Wikipedia: 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 dynamically typed languages (where values have types, but variables do not), equivalent behavior is provided by having a single null value.
NULL is frequently used to represent a missing value or invalid value, such as from a function that failed to return or a missing field in a database, as in NULL in SQL. In other words, NULL is undefined.
Primitive types such as integers and Booleans cannot generally be null, but the corresponding nullable types (nullable integer and nullable Boolean, respectively) can also assume the NULL value. This can be represented in ternary logic as FALSE, NULL, TRUE as in three-valued logic.