Zero value

from Wikipedia, the free encyclopedia

In computer science, a state that is supposed to indicate the absence of a value is called a zero value ( NULL , NIL or () for short ) . According to Edgar F. Codd, a distinction is made between two types of : the absence of a value because none exist (" property inapplicable "), or the absence because the value is not (yet) known (" value at present unknown "). A zero value stands for the absence of a value, but a zero value is also a value. NULL

The zero value is different from the number  0because it represents a value, i.e. information. In linguistic terms, the zero value is sometimes distinguished from the algebraic number 0 by pronunciation, in which (as in English ) [ 'nl ] is spoken to avoid misunderstandings.

example 1

The following example illustrates the meaning of NULLin databases and programs: Doctors should enter a diagnosis for each patient in a data table after they have examined them. What does it mean if no diagnosis is entered for a patient in this table? Is he healthy or just not examined yet?

In paper lists, it is therefore common to cross out empty fields to make it clear that the field was deliberately edited and that it should actually be empty. In databases, fields that have not yet been edited (or that have no value for other reasons) have the value NULL. As soon as you specifically enter a value, it disappears NULLand the entered value, which can also be empty (no diagnosis, i.e. healthy), is saved.

Example 2

Imagine that student phone numbers should be stored in a database or a long list. So you define that a column of the table can only contain numbers. If you come across a student who does not have a telephone, you would probably put a dash in his telephone number field instead of the telephone number, or perhaps the symbol "n / a" or a question mark. All of these characters are intended to mean: Value unknown or not available. This is exactly what the zero value does with electronic storage.

Representation in the computer

If you want to set such a "line" in a computer list, this "line" needs a digital form of representation. There are two approaches here:

Equating agreed valid values ​​with indefiniteness

A formally valid value of the field is arbitrarily selected as a zero value. Which is the zero value is either evident from the context or must be explicitly documented.

If quotations from apostles are given in a table, one could write numerical values ​​from 1 to 12 in the last column, which indicate which of the apostles of Jesus is quoted here. If it is unknown, one could now write down the value 13 or −1, meaning that it is not known which one it was, or whether it was a disciple of Jesus at all, or that no disciple of Jesus is definitely quoted.

The advantage of this method is that it basically saves storage space. The downside is that a value originally defined as a null value can conflict with an actual value. If you think of a zero value of 13 in the above list, it can happen that one day the apostle Paul is quoted and assigned the number 13, which now perhaps conflicts with a quotation from Goethe without being noticed.

This problem has occurred repeatedly in the past, including as a year 2000 problem .

Zero value as a fundamentally different value

In order to avoid the above problem, the null value can be unmistakably separated from the valid values ​​by introducing a special character that is always only a null value in all contexts.

A technical implementation is recommended in programming languages ​​that know variables of the pointer type, i.e. as a reference to the actual value. Now you can determine a certain place in the working memory, which is understood as a zero value - and only as a zero value. Among the many possibilities of an appointment, the appointment to zero is particularly suitable , because dereferencing a pointer pointing to address 0 leads to a crash on most operating system-machine combinations. If the above table column normally only contains pointers to telephone numbers, then it makes sense to give the null pointer the meaning that the empty telephone number is located at this point .

In the programming language  C the so-called null pointer exists (engl. For this purpose null pointer ). In the program text, a null pointer constant can be expressed by any integer constant expression (a constant whole number expression that must meet certain conditions) with the value 0, optionally with a cast after void*( ISO / IEC 9899 : 1999 6.3.2.3 Paragraph 3). The C standard library provides a macro NULLwhich expands to such an expression.

In C ++ , a null pointer constant cannot void*contain a cast to (ISO / IEC 14882: 1998 4.10, Paragraph 1), this also applies in C ++ to the standard macro NULL, which therefore usually only 0expands to an integer value in C ++ . Since this leads to other problems - so is this constant type intand not a pointer type - was in C ++ 11 introduced a new keyword for null pointer constant: nullptr. This constant is of its own data type ( std::nullptr_t), which can be converted into any pointer type (data, function pointer), but not into an integer expression.

In C # , nullthe default value for reference types such as Object, String or List is. When using these types, it is therefore important to initialize them before use, or to check before use whether the variable currently has the value null. Simple types such as int, on the other hand, cannot nullbe assigned and must therefore be assigned a real value such as 0. Since C # 2.0, however, there has also been the option of using so-called nullable types, which allow simple types such as int or bool to nullbe assigned.

Other programming languages, such as Java , provide a dedicated keyword for the null value. In some dynamically typed languages ​​such as Smalltalk there is a special predefined Null object that takes on the function of a canonical null value.

NULL in SQL databases

Classification and treatment according to the database logic

Relational database systems use a three-valued logic that is implemented in the query and update language SQL : Here, Unknown is the third truth value alongside False and True . The usual logical links And and Or are adapted by setting False = 0, True = 1 and Unknown = ½. Then between two truth values ​​a, b:, and .

In SQL, NULL is not a value because the fundamental property of values, namely being able to compare them with other values ​​of the same data type , does not produce the desired result. For example, the predicate Spalte = NULLalways results in unknown , even if there is a value in the column NULL. Instead, the IS NULLand predicates must be IS NOT NULLused NULLto test a value for .

On the one hand, one speaks of the so-called don't-know indeterminacy , meaning the already described ignorance of the value, on the other hand there is the so-called don't-care indeterminacy , which occurs in databases when a data set simply does not have a certain value needed. An example that is easy to see is the case of a document database in which a table with various multimedia documents is managed - for example books and CDs . In addition to general information such as name , subject , shelf location , the table can also have media-specific columns such as ISBN or artist . In this case, all entries about CDs would have a value in the ISBN column NULL, since usually only books have an ISBN. Accordingly, most of the books (except for audio books) in the column would performer a NULLstand, as books tend to be created by authors of performers.

The common doctrine is that the occurrence of don't-care uncertainties indicates errors in the design of the database. In short, the database should be planned and implemented from the outset in such a way that don't-care NULLs never occur.

In The Third Manifesto, Christopher J. Date and Hugh Darwen point out the problem of relational database systems and criticize the fact that the value in them is not unambiguous, as it can indicate either unknown or non-existence. In the Third Manifesto you explain how you can structure a relational database without the use of , by normalizing values ​​that can contain in your own relationship tables. NULLNULLNULLNULL

Distress zero

The language construct not null, borrowed from the database language SQL, describes the requirement that it NULLis impermissible in a particular context. In SQL, there is NOT NULLa very common constraint , i.e. an integrity condition that the software generally enforces.

In the description of user interfaces, it is indicated by the note not nullthat a data field in the output must always be filled and / or generally not be left empty when entering data. As a rule, the meaning of not empty is interpreted somewhat more generously in the latter case, so that a permissible value must be entered in each case, which, for example, can exclude sequences of spaces.

Different representations of the zero value

NILE

Some programming languages ​​(e.g. Pascal , Lisp , Smalltalk , Ruby , Objective-C , Lua , Scala ) use the designation nilinstead of Nullor null. Nil stands for English not in list, so not in the list . There are historical reasons for this, it comes from the programming language Lisp, which knows the binary tree linked in the leaf direction as the only data structure , but which is usually only used to represent simply linked lists . The name was also adopted for other programming languages, since the Latin word nil means nothing .

NIL is also a device in the Amiga computer system from Commodore . For example >NIL:, if you redirect a file , the output is practically shifted to nothing . This corresponds to / dev / null on Unix.

None

Furthermore, the designation None is sometimes used for a zero value, such as B. in the programming language Python .

Nothing

In the Visual Basic programming language, Nothing represents an uninitialized variable or a variable set to Nothing for the instance of a class. Check for zero or Nothing with: If IsNull (var_Myvar) Then ... If obj_MyClass Is Nothing Then ...

null / NULL / nullptr

In Java objects are only addressed via references. An object reference that does not refer to an object is nullassigned the value . This roughly corresponds to the use of the null pointer in C and C ++, which is represented by the macro NULLor - since C ++ 11 - by the keyword nullptr.

NaN

According to the IEEE 754 standard , the designation NaN ( not a number ) is used for floating point numbers with undefined or non-representable values . NaN are reserved bit patterns that are different from every permitted value. For example, NaN is the result of dividing “0 by 0”.

Sentinel or Guardian Value

A sentinel (like a NULLpointer ) cannot appear as a “real value”. It is sent the search argument in search loops so that the program logic always runs on a result "found". A query for the end of the list is thus made at the same time. After the loop it is examined how it ended; and if this was done via the Sentinel, the overall result is changed to "not found".

Demarcation

A zero value cannot be identified with the number zero because a zero value is not to be understood as a number. A zero value must also be distinguished from the empty set , since it is not to be understood as a set .

NUL

NUL is a common abbreviation for the null character .

Many operating systems (e.g. MS-DOS and Windows ) also use the name NUL to define a virtual output device that simply discards the recorded data. By redirecting to NUL, for example, undesired output of a command can be suppressed. This is equivalent to / dev / null on UNIX.

See also

Individual evidence

  1. ^ EF Codd: Extending the Database Relational Model to Capture More Meaning 1979, section 2.3. P. 7
  2. Kernighan / Ritchie: Programming in C (Second Edition) 1990, p. 99
  3. MSDN null(C # Reference ), accessed May 6, 2011
  4. MSDN Nullable Types (C # Programming Guide ), accessed May 6, 2011
  5. ^ The Third Manifesto - Date & Darwen , accessed May 6, 2011