Questions tagged [null]

Null means *nothing* or *unknown*, depending on context. Please use the "sql-null" tag for SQL specific questions.

"Null" has different meanings depending on context.

Set theory

Null is another name for the empty set, denoted by the symbol ∅. For this reason, some programming languages use null or nil for the empty list or empty tuple. Lisp uses nil to mean the empty list and the boolean value false.

Pointers and References

Null (or sometimes nil or None), in programming languages that support it, is the value of an uninitialized variable, a pointer that doesn't point to a meaningful memory address, or an object that fails to respond to any message.

Nullable references were invented by C.A.R. Hoare in 1965 as part of the Algol W language. Hoare later described his invention as a "billion-dollar mistake".

For more information, see Null pointer.

Agreeing with Hoare's sentiment, many languages don't have a special null value, choosing to use optional types instead.

Relational Databases

NULL as a special marker in SQL or a relational database stands in place of a value that is missing, or in a join means "no corresponding row." The operators IS NULL and IS NOT NULL are required for comparisons to a literal null: other comparisons between NULL and any value evaluate to "unknown."

For more information, see Null (SQL).

ASCII

Null or NUL is the name given to the character with ASCII code zero (0) - i.e. hex 00. In some languages, notably C, NUL is used to mark the end of a character string.

For more information, see Null character.

16208 questions
170
votes
5 answers

What's the better (cleaner) way to ignore output in PowerShell?

Let's say you have a method or a cmdlet that returns something, but you don't want to use it and you don't want to output it. I found these two ways: Add-Item > $null [void]Add-Item Add-Item | Out-Null What do you use? Which is the better/cleaner…
Hinek
  • 9,519
  • 12
  • 52
  • 74
168
votes
4 answers

ALTER TABLE, set null in not null column, PostgreSQL 9.1

I have a table with not null column, How to set a null value in this column as default? I mean, I want to do something like this: postgres=# ALTER TABLE person ALTER COLUMN phone SET NULL; but it shows: postgres=# ALTER TABLE person ALTER COLUMN…
Brian Brown
  • 3,873
  • 16
  • 48
  • 79
167
votes
29 answers

PHP json_decode() returns NULL with seemingly valid JSON?

I have this JSON object stored on a plain text file: { "MySQL": { "Server": "(server)", "Username": "(user)", "Password": "(pwd)", "DatabaseName": "(dbname)" }, "Ftp": { "Server": "(server)", …
167
votes
12 answers

How to tell if a string is not defined in a Bash shell script

If I want to check for the null string I would do [ -z $mystr ] but what if I want to check whether the variable has been defined at all? Or is there no distinction in Bash scripting?
Setjmp
  • 27,279
  • 27
  • 74
  • 92
166
votes
9 answers

In Objective-C why should I check if self = [super init] is not nil?

I have a general question about writing init methods in Objective-C. I see it everywhere (Apple's code, books, open source code, etc.) that an init method should check if self = [super init] is not nil before continuing with initialisation. The…
Jasarien
  • 58,279
  • 31
  • 157
  • 188
165
votes
20 answers

What reason is there to use null instead of undefined in JavaScript?

I've been writing JavaScript for quite a long time now, and I have never had a reason to use null. It seems that undefined is always preferable and serves the same purpose programmatically. What are some practical reasons to use null instead of…
Jimmy
  • 35,686
  • 13
  • 80
  • 98
164
votes
5 answers

String.IsNullOrWhiteSpace in LINQ Expression

I have the following code: return this.ObjectContext.BranchCostDetails.Where( b => b.TarrifId == tariffId && b.Diameter == diameter || (b.TarrifId==tariffId && !string.IsNullOrWhiteSpace(b.Diameter)) || (!b.TarrifId.HasValue) &&…
Hossein Moradinia
  • 6,116
  • 14
  • 59
  • 85
162
votes
10 answers

Is it better to return `undefined` or `null` from a javascript function?

I have a function which I have written which basically looks like this: function getNextCard(searchTerms) { // Setup Some Variables // Do a bunch of logic to pick the next card based on termed passed through what I'll call here as 'searchTerms'…
Jeremy Iglehart
  • 4,281
  • 5
  • 25
  • 38
162
votes
18 answers

Null vs. False vs. 0 in PHP

I am told that good developers can spot/utilize the difference between Null and False and 0 and all the other good "nothing" entities. What is the difference, specifically in PHP? Does it have something to do with ===?
stalepretzel
  • 15,543
  • 22
  • 76
  • 91
160
votes
7 answers

How to do method overloading for null argument?

I have added three methods with parameters: public static void doSomething(Object obj) { System.out.println("Object called"); } public static void doSomething(char[] obj) { System.out.println("Array called"); } public static void…
Phani
  • 5,319
  • 6
  • 35
  • 43
156
votes
9 answers

Overriding == operator. How to compare to null?

Possible Duplicate: How do I check for nulls in an ‘==’ operator overload without infinite recursion? There is probably an easy answer to this...but it seems to be eluding me. Here is a simplified example: public class Person { public string…
Flipster
  • 4,373
  • 4
  • 28
  • 36
149
votes
4 answers

Is a null reference possible?

Is this piece of code valid (and defined behavior)? int &nullReference = *(int*)0; Both g++ and clang++ compile it without any warning, even when using -Wall, -Wextra, -std=c++98, -pedantic, -Weffc++... Of course the reference is not actually null,…
peoro
  • 25,562
  • 20
  • 98
  • 150
148
votes
16 answers

Java null check why use == instead of .equals()

In Java I am told that when doing a null check one should use == instead of .equals(). What are the reasons for this?
Jim Jeffries
  • 9,841
  • 15
  • 62
  • 103
147
votes
11 answers

Does free(ptr) where ptr is NULL corrupt memory?

Theoretically I can say that free(ptr); free(ptr); is a memory corruption since we are freeing the memory which has already been freed. But what if free(ptr); ptr=NULL; free(ptr); As the OS will behave in an undefined manner I cannot get an…
Vijay
  • 65,327
  • 90
  • 227
  • 319
147
votes
9 answers

MongoDB: How to query for records where field is null or not set?

I have an Email document which has a sent_at date field: { 'sent_at': Date( 1336776254000 ) } If this Email has not been sent, the sent_at field is either null, or non-existant. I need to get the count of all sent/unsent Emails. I'm stuck at…
Andrew
  • 227,796
  • 193
  • 515
  • 708