Null is the representation of nothingness, the abyss or undefined objects in computing. This is a pervasive feature in the design of programming languages, databases, operating systems and computing platforms.
Examples of NullThe following are common examples of how null is used in computing.
|Null Value||A null value indicates that a variable or field has not been set. For example, in a database of guest responses to wedding invitations, a value of null might indicate the guest did not respond.|
|Null Pointer||A null pointer indicates an object has not been created. For example, if you query a database and there are no results, a null pointer may be returned to indicate an empty result set.|
|Nullable Type ||A datatype in a programming language that can be set to null. A datatype that is not nullable can be tricky because there may be no universal way to flag that the variable has not been initialized.|
|Null Character||A character of text that represents nothing such that it is not displayed. This may be used to delimit strings with a non-printing character.|
|Null String||A string that has not been initialized. This often has a different meaning from the empty string, or "". For example, a voice recognition app could use empty string to indicate that the user didn't say anything and null to indicate that the microphone could not be accessed.|
|Null Device||A null device such as /dev/null on linux is a way to send something into the abyss. For example, if you don't want to print errors on to your screen or into a file you can simply redirect them to /dev/null and they will disappear.|
|Null Route||A null route is a network route for the abyss. This is a way to discard a message for purposes such as information security.|
|Null Pointer Exception||An error that occurs if code tries to use an object that hasn't been initialized. For example, a connection to a database that hasn't been established.|
Why Null is UnpopularNull is a special case that often requires handling in code. If you try to perform an operation on a object that hasn't been created, it may throw a null pointer exception. As a special case, null requires a lot of attention from programmers. When errors occur, they are often null related such as a null pointer exception. This leads may software developers, administrators and users to view null as an annoyance.
Why Null is UsefulNull is an essential part of the semantics and functionality of a computing environment. Null values make it explicitly clear that something hasn't been created or initialized in a way that can't be ignored. A computing platform can be designed to always create things with defaults, leaving no possibility of null. However, this is error prone as you end up using default values and objects thinking that they are meaningful when they aren't.
Example #1Null pointer exceptions are meaningful as they tell you that something hasn't been initialized and code failed to handle this. In an environment with default values in place of nulls, errors tend to be more difficult to detect and trace. They can also have more business impact. For example, a banking website that initializes your balance to 0 when it can't connect to a backend system may make customers nervous if not angry. This is the type of error that surfaces without the elegant feature of null that explicitly tells you a value hasn't been set. In our banking example, a null could be handled to tell the customer their balance isn't currently available. If the null weren't handled, resulting in a null pointer exception, an error page might be shown. This is generally better than telling a customer their balance is 0 when it isn't.
Example #2A null device on an operating system is a way to send data to nowhere. One of the advantages of a digital environment as opposed to the physical world is that garbage can instantly disappear without a trace. A null device is an elegant way to achieve this.
This is the complete list of articles we have written about coding.
If you enjoyed this page, please consider bookmarking Simplicable.
© 2010-2023 Simplicable. All Rights Reserved. Reproduction of materials found on this site, in any form, without explicit permission is prohibited.
View credits & copyrights or citation information for this page.