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
7
votes
5 answers

Having a static "NULL" object in Java?

While browsing through some code for a library I'm using, I came across this code snippet: public class SomeClass { private static final class Null { /* ... */ } public static final Object NULL = new Null(); } Is this a…
Ivan
  • 10,052
  • 12
  • 47
  • 78
7
votes
1 answer

Shouldn't Rails find_by_ methods return an empty array instead of nil?

Shouldn't Rails find_by_ methods return an empty array instead of nil? It's normal for there to be no records that match the find_by_ condition, but returning nil doesn't make sense. Because then in my views errors are raised by sensible code…
Arcolye
  • 6,968
  • 4
  • 34
  • 28
7
votes
1 answer

How does foo(&nil) behave differently than foo(&"not a proc")?

I found out from heckle that [1, 2, 3].each(&nil) doesn't cause any errors - it just returns an enumerator. By contrast, [1, 2, 3].each(&"") raises TypeError: wrong argument type String (expected Proc) Also, &nil causes block_given? to return…
Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
7
votes
2 answers

Comparisons with NULLs in SQL

ANSI-92 SQL mandates that comparisons with NULL evaluate to "falsy," eg: SELECT * FROM table WHERE field = NULL SELECT * FROM table WHERE field != NULL Will both return no rows because NULL can't be compared like that. Instead, the predicates IS…
NullUserException
  • 83,810
  • 28
  • 209
  • 234
7
votes
3 answers

How to make a generic method allow returning null and accept enum?

How to make the following extension works? I'm binding the ComboBoxe to an enum and in this case it doesn't compile because it returns null. public static T GetSelectedValue(this ComboBox control) { if (control.SelectedValue == null) …
French Boy
  • 1,471
  • 3
  • 18
  • 23
7
votes
3 answers

Passing null to non-nullable internal function parameters - Updating Existing Code Base to php 8.1

I am just getting started on upgrading my code to be php 8.1 compatible. I have many pieces of code where I am passing potentially null values to internal functions. if (strlen($row) > 0) { ... } Where $row comes from a source that may have…
mseifert
  • 5,390
  • 9
  • 38
  • 100
7
votes
6 answers

Comparing a Null to another value in MySQL Trigger

So here is my issue I am comparing new and old values when a table row is being updated. But the new or old value will sometimes be null. So the code below doesn't work. Can can I remedy this issue? Thank You BEFORE UPDATE ON mytable FOR EACH…
dan
  • 73
  • 1
  • 3
7
votes
2 answers

NULL-free shellcode

I am trying to convert an assembly program I wrote into NULL-free shellcode. However, I am unsure how to go about this for certain instructions. Some of them (in Intel syntax) include: push 0x1000 and mov BYTE [eax],0x31 I want to avoid using…
cytinus
  • 5,467
  • 8
  • 36
  • 47
7
votes
0 answers

Nginx log full of `NULL` characters

I'm running Nginx in a Docker container, and my error log keeps filling up with NULL characters, so it looks like this: I had Nginx and PHP containers both set to output errors to error.log. When I set PHP to use a separate log file, I get fewer…
And Finally
  • 5,602
  • 14
  • 70
  • 110
7
votes
1 answer

MySQL/InnoDB Plugin: Will NULL values for VARCHAR fields still take up storage spaces?

I'm using InnoDB Plugin in the Barracuda file format with: ROW_FORMAT=DYNAMIC If I define a field as VARCHAR(255), and then insert a record that has a NULL value for that field, will that record still use 255 bytes in storage for the VARCHAR field?…
Continuation
  • 12,722
  • 20
  • 82
  • 106
7
votes
5 answers

Insert Null value to the Integer Column

Through the front end I want to insert NULL value to the Column whose DataType is Int. I used like this: POP.JobOrderID = Convert.ToInt32(DBNull.Value); But I cannot Insert Null value, it throws error such as "Object cannot be cast from DBNull to…
thevan
  • 10,052
  • 53
  • 137
  • 202
7
votes
2 answers

Ambiguous overload of pointer and integer?

The following overloaded function, void foo(const void*) { printf("first"); } void foo(unsigned int) { printf("second"); } generates an ambiguous overload in this case foo((int)0); but not in this one foo((int)1); Why? Is it because people…
Sneppy
  • 379
  • 5
  • 20
7
votes
3 answers

Reference pointing to a Null-object

I saw this discussion - Checking for a null object in C++ and I was surprised that no one talked about when reference can point to a null object. In our code, we use null objects routinely. There are functions as follows which return nullObj. const…
cppcoder
  • 1,194
  • 4
  • 16
  • 30
7
votes
7 answers

About the non-nullable types debate

I keep hearing people talk about how non-nullable reference types would solve so many bugs and make programming so much easier. Even the creator of null calls it his billion dollar mistake, and Spec# has introduced non-nullable types to combat this…
zildjohn01
  • 11,339
  • 6
  • 52
  • 58
7
votes
4 answers

Checking if a variable is empty c#

I have a pretty basic question but it is doing my nut in!!!! I have created a variable which checks my data table checks to see if an item using my page control ID already exists. IF it does I then want to warn my user that they have already chosen…
Callum
  • 3,221
  • 3
  • 19
  • 18