Jump to content

Void safety: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
m Tag uncat using AWB
m Changed word "anterior" with "older" to use an english word
 
(42 intermediate revisions by 28 users not shown)
Line 1: Line 1:
'''Void safety''' is a guarantee within an [[object-oriented language|object-oriented programming language]] that that no [[reference (computer science)|object references]] will have [[null pointer|''null'' or ''void'']] values.
'''Void safety''' (also known as '''null safety''') is a guarantee within an [[object-oriented language|object-oriented programming language]] that no [[reference (computer science)|object references]] will have [[null pointer|''null'' or ''void'']] values.


In [[object-oriented language]]s, access to objects is achieved through [[reference (computer science)|references]] (or, equivalently, [[pointer (computing)|pointers]]). A typical call is of the form:
In object-oriented languages, access to objects is achieved through [[reference (computer science)|references]] (or, equivalently, [[pointer (computer programming)|pointers]]). A typical call is of the form:


x.f(a, ...)
x.f(a, ...)
Line 7: Line 7:
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 handling|exception]], often resulting in [[crash (computing)|abnormal termination]] of the program.
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 handling|exception]], often resulting in [[crash (computing)|abnormal termination]] of the program.


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


==History==
==History==
In a 2009 talk, [[C.A.R. Hoare|Tony Hoare]] traced the invention of the null pointer to his design of the [[Algol W]] language (although the [[Lisp (programming language)|Lisp language]] had the NIL value as early as 1959) and called it a "mistake":
In a 2009 talk, [[C.A.R. Hoare|Tony Hoare]] traced the invention of the [[null pointer]] to his design of the [[ALGOL W]] language and called it a "mistake":


{{quote|I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language ([[ALGOL W]]). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.<ref name="Hoare">C.A.R. Hoare: ''Null References: The Billion Dollar Mistake'', abstract of a talk at QCon London, 9–12 March 2009, available [http://qconlondon.com/london-2009/presentation/Null+References:+The+Billion+Dollar+Mistake online]</ref>}}
{{quote|I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.<ref name="Hoare">C.A.R. Hoare: ''Null References: The Billion Dollar Mistake'', abstract of a talk at QCon London, 9–12 March 2009, available [https://web.archive.org/web/20090119110704/http://qconlondon.com/london-2009/presentation/Null+References%3A+The+Billion+Dollar+Mistake online]</ref>}}


Bertrand Meyer introduced the term "void safety".<ref>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 [http://se.ethz.ch/~meyer/publications/lncs/attached.pdf online]</ref>
[[Bertrand Meyer]] introduced the term "void safety".<ref>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 [http://se.ethz.ch/~meyer/publications/lncs/attached.pdf online]</ref>


==Void safety in programming languages==
==In programming languages==
An early attempt to guarantee void safety was the design of the [[Self (programming language)|Self programming language]].
An early attempt to guarantee void safety was the design of the [[Self (programming language)|Self programming language]].


The [[Eiffel (programming language)|Eiffel language]] is void-safe according to its [[International Standards Organization|ISO]]-[[Ecma International|ECMA]] standard; the [[Eiffel (programming language)#Void-safety|void-safety mechanism]] is implemented in [[EiffelStudio]] starting with [http://docs.eiffel.com/book/eiffelstudio/major-changes-between-ise-eiffel-60-and-ise-eiffel-61 version 6.1] and using a modern syntax starting with [http://docs.eiffel.com/book/eiffelstudio/major-changes-between-ise-eiffel-63-and-ise-eiffel-64 version 6.4].
The [[Spec Sharp|Spec# language]], a research language from Microsoft Research, has a notion of "non-nullable type" addressing void safety.


The Spec# language, a research language from Microsoft Research, has a notion of "non-nullable type" addressing void safety.
The [[Eiffel (programming language)|Eiffel language]] is void-safe according to its [[International Standards Organization|ISO]]-[[Ecma International|ECMA]] standard; the void-safety mechanism is implemented in [[EiffelStudio]] starting with version 6.1.[Reference missing]
The [[F Sharp (programming language)|F# language]], a functional-first language from Microsoft Research running on .NET framework, is void-safe except when interoperating with other .NET languages.<ref>{{cite web |last1=Syme |first1=Don |title=Quote of the Week: "What can C# do that F# cannot?" |url=https://blogs.msdn.microsoft.com/dsyme/2013/03/25/quote-of-the-week-what-can-c-do-that-f-cannot/ |accessdate=7 September 2018}}</ref>

===Null safety based in union types===

Since 2011 several languages support [[union type]]s and [[intersection type]]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 (programming language)|Ceylon]], followed soon by [[TypeScript]].

The [[C Sharp (programming language)|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.<ref>{{cite web |title=<nowiki>Nullable reference types | Microsoft Docs</nowiki> |url=https://docs.microsoft.com/en-us/dotnet/csharp/nullable-references |accessdate=12 March 2021}}</ref>

The Google's [[Dart (programming language)|Dart]] language implements it since its version 2.0, in August 2018<ref>{{Cite web|url=https://medium.com/dartlang/dart-2-stable-and-the-dart-web-platform-3775d5f8eac7|title=Announcing Dart 2 Stable and the Dart Web Platform|last=Moore|first=Kevin|date=2018-08-07|website=Dart|access-date=2018-08-08}}</ref><ref>{{cite web |title=<nowiki>Sound null safety | Dart</nowiki> |url=https://dart.dev/null-safety |accessdate=12 March 2021}}</ref>

Other languages that use null-safe types by default include JetBrains' [[Kotlin (programming language)|Kotlin]],<ref>{{cite web |title=Null safety—Kotlin |url=https://kotlinlang.org/docs/null-safety.html |accessdate=12 March 2021}}</ref> [[Rust (programming language)|Rust]],<ref>{{Cite web|title=Defining an Enum - The Rust Programming Language|url=https://doc.rust-lang.org/book/ch06-01-defining-an-enum.html|access-date=2021-06-26|website=doc.rust-lang.org}}</ref> and Apple's [[Swift (programming language)|Swift]].

==See also==
*[[Nullable type]]
*[[Option type]]
*[[Safe navigation operator]]


==References==
==References==
<references/>
<references/>


[[Category:Object-oriented programming]]
{{Uncategorized stub|date=September 2010}}





Latest revision as of 23:03, 21 August 2023

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[edit]

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":

I call it my billion-dollar mistake. It was the invention of the null reference in 1965. At that time, I was designing the first comprehensive type system for references in an object oriented language (ALGOL W). My goal was to ensure that all use of references should be absolutely safe, with checking performed automatically by the compiler. But I couldn't resist the temptation to put in a null reference, simply because it was so easy to implement. This has led to innumerable errors, vulnerabilities, and system crashes, which have probably caused a billion dollars of pain and damage in the last forty years.[1]

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

In programming languages[edit]

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.[3]

Null safety based in union types[edit]

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.[4]

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

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

See also[edit]

References[edit]

  1. ^ C.A.R. Hoare: Null References: The Billion Dollar Mistake, abstract of a talk at QCon London, 9–12 March 2009, available online
  2. ^ 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
  3. ^ Syme, Don. "Quote of the Week: "What can C# do that F# cannot?"". Retrieved 7 September 2018.
  4. ^ "Nullable reference types | Microsoft Docs". Retrieved 12 March 2021.
  5. ^ Moore, Kevin (2018-08-07). "Announcing Dart 2 Stable and the Dart Web Platform". Dart. Retrieved 2018-08-08.
  6. ^ "Sound null safety | Dart". Retrieved 12 March 2021.
  7. ^ "Null safety—Kotlin". Retrieved 12 March 2021.
  8. ^ "Defining an Enum - The Rust Programming Language". doc.rust-lang.org. Retrieved 2021-06-26.