Null

From Jonathan Gardner's Tech Wiki
Jump to: navigation, search

Introduction

The "null" value and data type is the most basic data type in all of computer science.

Interpretation

Null can be interpreted in any number of ways.

In SQL, it is generally interpreted as "no such data". This could mean that the data is missing, the data doesn't exist, or that the data hasn't been added yet. It could also mean that the data is invalid.

In other languages, it is interpreted according to the context. For instance, when a Java function returns null, it means that the operation probably failed even though it didn't throw an exception.

Representation

NULL is usually considered a separate data type from all other data types.

C/C++ represent null with a pointer to 0, as opposed to the integer 0. This representation is tricky since a pointer to 0 isn't a pointer at all. You have to test all pointers to see if they are null or a valid pointer before dereferencing them.

Implementation

Language Representation
SQL NULL
Python None
C/C++ pointer to 0
Perl undef
Javascript undefined, null
Java null
Lisp NIL
PHP NULL

Behavior

Many languages treat null like 0.

Other languages (SQL) treat null as a special value. Any mathematical operation on null yields null.

It is important to find out how the language treats it.