🌐
Merriam-Webster
merriam-webster.com › dictionary › null
NULL Definition & Meaning - Merriam-Webster
Let’s be honest: null is kind of a nothing word. That’s not a judgment—it was literally borrowed into English from the Anglo-French word nul, meaning "not any." That word, in turn, traces to the Latin word nullus, from ne-, meaning "not," and ullus, meaning "any."
🌐
Wikipedia
en.wikipedia.org › wiki › Null
Null - Wikipedia
1 month ago - Null character, the zero-valued ASCII character, also designated by NUL, often used as a terminator, separator or filler.
🌐
freeCodeCamp
freecodecamp.org › news › a-quick-and-thorough-guide-to-null-what-it-is-and-how-you-should-use-it-d170cea62840
A quick and thorough guide to ‘null’: what it is, and how you should use it
June 12, 2018 - In a simple and flawless world, null would simply mean that Alice actually doesn't have an email address. When we write code, the reason why a reference points to null is often irrelevant. We just check for null and take appropriate actions. For example, suppose that we have to write a loop that sends emails for a list of persons.
🌐
Etymonline
etymonline.com › word › null
Null - Etymology, Origin & Meaning
"nothing," 1957; "insignificant person," 1933, from use of Zilch as a generic comical-sounding surname for an insignificant person (especially Joe Zilch). There was a Mr. Zilch (1931), comic character in the magazine "Ballyhoo," and the use ...
🌐
Urban Dictionary
urbandictionary.com › define.php
Urban Dictionary: Null
Meaning NO! Ex: Aye Rod can I borrow your car to go the store, NULL!
🌐
VICE
vice.com › home › when a ‘null’ value happens to be a person
When a 'Null' Value Happens to Be a Person
July 29, 2024 - Null has meaning—a whole lot of it, actually—but its whole purpose in life is to indicate no value.
🌐
Dictionary.com
dictionary.com › browse › null
NULL Definition & Meaning | Dictionary.com
Null definition: without value, effect, consequence, or significance.. See examples of NULL used in a sentence.
🌐
Wiktionary
en.wiktionary.org › wiki › null
null - Wiktionary, the free dictionary
Something that has no force or meaning. (computing) The null character; the ASCII or Unicode character (␀), represented by a zero value, which indicates no character and is sometimes used as a string terminator.
Top answer
1 of 7
42

I have seen database interfaces (e.g. framework libraries) that return 'null' as a string for null columns. I believe there was a flag that would turn this on or off for debugging. This flag allows developers to easily determine if the empty field was a result of a null value or an empty value. This is a bad setting, especially in production, and would explain the issues explained in the article.

The reverse processing of converting 'null' to a null value should generate an application error for a name field. I would expect this to be rather quickly resolved.

2 of 7
24

There's a good chance that a good chunk of your confusion stems from the journalist's. The article talks about problems using entire application systems, not just databases. Completely reasonable since this is a piece of writing aimed at mass consumption, but technical details are glossed over or misunderstood by the author.

Likely a number of these issues are caused at the application layer, rather than the DB's API. Magic values are an anti-pattern which is ridiculously hard to stamp out of the industry. Very easily some programmer could have written a condition along the lines of "someone typed 'null'? They must mean there's no value, because that's what null means!" A misguided attempt at preventing SQL injection could also be responsible for the mentioned mistreatment of Null, or the Hawaiian last name which contains a single quote, which is also the standard SQL string delimiter.

An application which incorrectly transforms these values into NULL or an empty string can easily create errors if business logic or DB constraints expect something different. This naturally results in exactly the frustrating user experience described in the article.

🌐
WIRED
wired.com › opinion › cybersecurity › hello, i'm mr. null. my name makes me invisible to computers
Hello, I'm Mr. Null. My Name Makes Me Invisible to Computers | WIRED
November 5, 2015 - As a technology journalist, being a Null has served me rather well. (John Dvorak, you know what I'm talking about!) The geek connotations provide a bit of instant nerd cred—to the point where more than one person has accused me of using a nom de plume to make me seem like a bigger nerd than I am.
Find elsewhere
Top answer
1 of 8
505

TL;DR

The key to understanding what null! means is understanding the ! operator. You may have used it before as the "not" operator. However, since C# 8.0 and its new "nullable-reference-types" feature, the operator got a second meaning. It can be used on a type to control Nullability, it is then called the "Null Forgiving Operator".

Basically, null! applies the ! operator to the value null. This overrides the nullability of the value null to non-nullable, telling the compiler that null is a "non-null" type.


Typical usage

Assuming this definition:

class Person
{
    // Not every person has a middle name. We express "no middle name" as "null"
    public string? MiddleName;
}

The usage would be:

void LogPerson(Person person)
{
    Console.WriteLine(person.MiddleName.Length);  // WARNING: may be null
    Console.WriteLine(person.MiddleName!.Length); // No warning
}

This operator basically turns off the compiler null checks for this usage.

Technical Explanation

The groundwork that you will need to understand what null! means.

Null Safety

C# 8.0 tries to help you manage your null-values. Instead of allowing you to assign null to everything by default, they have flipped things around and now require you to explicitly mark everything you want to be able to hold a null value.

This is a super useful feature, it allows you to avoid NullReferenceExceptions by forcing you to make a decision and enforcing it.

How it works

There are 2 states a variable can be in - when talking about null-safety.

  • Nullable - Can be null.
  • Non-Nullable - Cannot be null.

Since C# 8.0 all reference types are non-nullable by default. Value types have been non-nullable since C# 2.0!

The "nullability" can be modified by 2 new (type-level) operators:

  • ! = from Nullable to Non-Nullable
  • ? = from Non-Nullable to Nullable

These operators are counterparts to one another. The Compiler uses the information that you define with these operators to ensure null-safety.

Examples

? Operator usage.

This operator tells the compiler that a variable can hold a null value. It is used when defining variables.

  • Nullable string? x;

    • x is a reference type - So by default non-nullable.
    • We apply the ? operator - which makes it nullable.
    • x = null Works fine.
  • Non-Nullable string y;

    • y is a reference type - So by default non-nullable.
    • y = null Generates a warning since you assign a null value to something that is not supposed to be null.

Nice to know: Using object? is basically just syntactic sugar for System.Nullable<object>

! Operator usage.

This operator tells the compiler that something that could be null, is safe to be accessed. You express the intent to "not care" about null safety in this instance. It is used when accessing variables.

string x;
string? y;
  • x = y
    • Illegal! Warning: "y" may be null
    • The left side of the assignment is non-nullable but the right side is nullable.
    • So it does not work, since it is semantically incorrect
  • x = y!
    • Legal!
    • y is a reference type with the ? type modifier applied so it is nullable if not proven otherwise.
    • We apply ! to y which overrides its nullability settings to make it non-nullable
    • The right and left side of the assignment are non-nullable. Which is semantically correct.

WARNING The ! operator only turns off the compiler-checks at a type-system level - At runtime, the value may still be null.

Use carefully!

You should try to avoid using the Null-Forgiving-Operator, usage may be the symptom of a design flaw in your system since it negates the effects of null-safety you get guaranteed by the compiler.

Reasoning

Using the ! operator will create very hard to find bugs. If you have a property that is marked non-nullable, you will assume you can use it safely. But at runtime, you suddenly run into a NullReferenceException and scratch your head. Since a value actually became null after bypassing the compiler-checks with !.

Why does this operator exist then?

There are valid use-cases (outlined in detail below) where usage is appropriate. However, in 99% of the cases, you are better off with an alternative solution. Please do not slap dozens of !'s in your code, just to silence the warnings.

  • In some (edge) cases, the compiler is not able to detect that a nullable value is actually non-nullable.
  • Easier legacy code-base migration.
  • In some cases, you just don't care if something becomes null.
  • When working with Unit-tests you may want to check the behavior of code when a null comes through.

Ok!? But what does null! mean?

It tells the compiler that null is not a nullable value. Sounds weird, doesn't it?

It is the same as y! from the example above. It only looks weird since you apply the operator to the null literal. But the concept is the same. In this case, the null literal is the same as any other expression/type/value/variable.

The null literal type is the only type that is nullable by default! But as we learned, the nullability of any type can be overridden with ! to non-nullable.

The type system does not care about the actual/runtime value of a variable. Only its compile-time type and in your example the variable you want to assign to LastName (null!) is non-nullable, which is valid as far as the type-system is concerned.

Consider this (invalid) piece of code.

object? null;
LastName = null!;
2 of 8
37

null! is used to assign null to non-nullable variables, which is a way of promising that the variable won't be null when it is actually used.

I'd use null! in a Visual Studio extension, where properties are initialized by MEF via reflection:

[Import] // Set by MEF
VSImports vs = null!;
[Import] // Set by MEF
IClassificationTypeRegistryService classificationRegistry = null!; 

(I hate how variables magically get values in this system, but it is what it is.)

I also use it in unit tests to mark variables initialized by a setup method:

public class MyUnitTests
{
    IDatabaseRepository _repo = null!;

    [OneTimeSetUp]
    public void PrepareTestDatabase()
    {
        ...
        _repo = ...
        ...
    }
}

If you don't use null! in such cases, you'll have to use an exclamation mark every single time you read the variable, which would be a hassle without benefit.

Note: cases where null! is a good idea are fairly rare. I treat it as somewhat of a last resort.

🌐
Reddit
reddit.com › r/nonbinary › anyone else consider their gender 'null'?
r/NonBinary on Reddit: Anyone else consider their gender 'null'?
February 4, 2024 -

So the label 'nonbinary' is one I felt has fit for a while, though it has no meaningful impact on my day to day life. Anyone who knows me IRL has no reason to think of me as anything other than a somewhat GNC cis man, and when it comes to pronouns it's literally 'call me whatever the heck you want' if anyone asked me.

I never thought it of it much beyond that but over time I've realised what 'gender' fits me.

Nullgender.

Not agender. Not linked to male or female in any way. Just not there, like a NULL 'value' in a data set (I work with data sets all the time in my day job).

Not exactly a life-changing revelation, but nice to put a stronger label on it.

Anyone else feel similar?

🌐
Quora
quora.com › What-does-null-mean-in-messaging-I-sent-someone-a-DM-in-GroupMe-and-at-the-bottom-it-said-read-null-then-when-I-closed-the-app-and-opened-it-again-it-just-said-read-What-does-this-mean-Did-they-receive-the-message
What does ‘null’ mean in messaging? I sent someone a DM in GroupMe, and at the bottom, it said “read (null)” then when I closed the app a...
Answer (1 of 4): Null is a programming term like ‘this space intentionally left blank’ My guess is the program expects to find ‘timestamp’ data there to know when it was read. The first time it dutifully reported ‘null’ the second time around it may have be processed by other code ...
🌐
Collins Dictionary
collinsdictionary.com › dictionary › english › null
NULL definition and meaning | Collins English Dictionary
6 meanings: 1. without legal force; invalid; (esp in the phrase null and void) 2. without value or consequence; useless 3..... Click for more definitions.
🌐
LSD.Law
lsd.law › define › null
What is null? Simple Definition & Meaning
A lawyer is a person who writes a 10,000-word document and calls it a 'brief'.
🌐
TheFreeDictionary.com
thefreedictionary.com › null
Null - definition of null by The Free Dictionary
Define null. null synonyms, null pronunciation, null translation, English dictionary definition of null. adj. 1. Having no legal force; invalid: render a contract null and void. 2. Of no consequence, effect, or value; insignificant.
🌐
Vocabulary.com
vocabulary.com › dictionary › null
Null - Definition, Meaning & Synonyms | Vocabulary.com
From the Latin nullus, meaning "not any," poor, powerless null is not actually there at all. Or if it was, it’s gone now. Because null is basically nothing, zip, zilch, nada, and nix. What could be worse? Maybe being "null and void," which is a legal term making something really, really null.