Zero means null
In Computing, the design anti-pattern Zero means null or Default value as undefined occurs when an application or database allows without checking that a value will never occur and thus can be used to indicate the absence of a value.
The first option to take is to use, if it exists, in the database management system or development language a representation for the null value. If it doesn't exist, dig into the application specification to make sure that there is some value that belongs to the data type but not the data domain, and take any of those values as null. Finally, if there is no usable value as undefined, extend the representation to indicate, for example with a Boolean value, when the field is defined.
Examples
- An app designer imagines that No one will report from coordinates 0.0 so the pair 0,0 gives the meaning of They don't know the coordinates.
- A user complains because every time he draws the meridians, there is one that is always missing.
It is more common than imagined for applications to take particular values to represent the undefined value, for example -1 assuming that values will never be negative or one of the strings "", " (null)", "XXXX", etc. to represent an undefined text.
Alternatives
Many programming languages allow you to define types that can take a null value as part of the type's values, unlike all others.
- In Haskell
data Maybe a = Just a |
- In Ocaml and Standard ML
type 'a option = Some of 'a | None
Other languages such as Java, SQL, etc. they have a notion of null value that can be used directly. For example (in Java)
Integer value = null;
Languages such as Perl and Python have null values although they behave like the false
value in some contexts. To differentiate a value from null in these languages can be asked explicitly. For example (in Python)
if value is None:
Contenido relacionado
Netscape
Intel pentium
FPS