What does NULL really mean?

Asked

Viewed 16,518 times

50

Many people talk about what NULL is, but after all, what is its true meaning?

  • 3

    Related: http://answall.com/questions/2407/qual-a-diferen%C3%A7a-entre-null-e-undefined

  • 2

    @Duds, NULL is NULL. Banter

  • 8

    "Many talk about what is NULL" many what? By the way, you removed the language tags but left caracteristica-linguagem, it is difficult to answer in the abstract (since different languages deal with NULL, null or nil differently), you want an overview of the concept (i.e. a more "philosophical" answer) or you want to know the practical application in some specific context (e.g. programming languages vs. database).

  • I want a more "philosophical" definition@mgibsonbr, NULL has never been clearer to me before

  • 1

    Related: http://answall.com/questions/74866/no-php-null-%C3%A9-a-constant-or-a-keyword

  • 1

    Related: http://answall.com/q/2296/215

Show 2 more comments

6 answers

71

Ensō, o símbolo da iluminação, força, elegância, o universo e o vazio

So said the Master Programmer: Even if the program has only three lines, someday someone will have to maintain.


Legend has it that in a remote province there was a monastery where the Master Programmer shared his teachings. One of his dialogues was about NULL.

'Master', asked Wu Junior Court Analyst, 'What does it mean NULL?'

'You ask me about the indecipherable', answered the Master Programmer. 'NULL is what never was, and never will be.'

'It’s her reflection in a lake that never existed.
The son who was never conceived.
The love you never called yours, because you lacked courage.
It’s the dark of the world, and beyond.'

'It’s the object I never saved?'

'No. This object was destroyed by Garbage Collector, after being Disposed();.'

'It’s the variable I declared, but I never initialized?'

'No. In the uninitialized variable there is the potential for greatness; its future is not yet written, and perhaps does not exist - but its place is reserved in the history of the world. It is undefined, or uninitialized.'

'And why so many languages implement NULL?'

'Because we need to admit our ignorance. What we do not know, cannot be described; what has no value cannot be evaluated.'

'So why not use zero, or a blank?'

'You want a zero because your mind can’t abandon the concept of something. It associates zero, a numerical absence, with nothingness - and even nothingness is more than NULL. Your code will then carry an entropy seed. It will be separated from the Zen, and on the way to becoming spaghetti code.'

'But, Master... then why, in PHP, (array() == null);?'

The Master Programmer then sighed. This would be a long afternoon.

  • 8

    I knew you were gonna do this and you’re gonna get more votes than my :D

  • 5
  • 4

    @bigown ah, but it’s such an interesting subject! was worth the prose version. =)

  • @Onosendai, for this I did not expect! Very good! D

  • @Math thanks for the link I added to the reply. =)

  • 19

    That’s the most mythical answer I’ve ever read here at Sopt.

  • 1

    @It’s about NULL. It could only be mysterious...

  • 5

    This master of programming is a philosopher

Show 3 more comments

51


The question was edited when there were already several answers, including one that was most appropriate to her initial scope. It’s still valid, but I need to put this on for those who don’t understand why I’m talking about Java and C++

null in Java, or NULL (in C and C++ old style) or nullptr (C++ modern) is the indetermination of a value. In the context of the question it is always represented by a pointer valued 0, that is, pointing to an address that was agreed to be invalid in memory. So the code knows it can’t access anything.

In this context the null has a value as stated above. But it does not point to a valid object that should have a significant value for the type it represents. It indicates that there is no corresponding object for that value.

Null is not a type in these languages, and also does not mean absence of type. It can be a type in other languages.

null == null and is different from everything else (in these languages).

Obviously trying to access something in the object that should exist in a variable with null value will produce an error, since there is nothing there to access.

In other contexts, it may have a more specific definition and a little different from this.

In SQL, for example, it only indicates the value indetermination. It has nothing of this memory thing, another object. Some mistakenly say that it is nothing, or worthless, but that is not correct. There are cases where people use null to give some specific semantics and say it’s "not applicable", "not existing", "not defined", or something like that. But this is something specific to the application.

Null may only be the terminator of strings standard C (the standard of string most used). It is used because it is an invalid character in any text.

Other "millions" of definitions can be found here.

Use in other contexts.

He is called "the mistake of a trillion dollars" (Okay, I updated the figures, the original speaks in billion)

Null is not the same thing as Null Object.

Modern languages are avoiding their use, at least by default.

It is common for him to break the static typing and type security of the languages that preach it.

Auxiliary reading: What is the difference between pointer and reference?

0 X NULL

  • 1

    Something that means nothing in language has so many meanings, rsrsrs

  • 3

    -1 because I only found 30 definitions about what is 'null' in this link you passed :D

  • 6

    @Marcelobonifazio I only hope that people are as humorous as you and do not read this and Egative :D

  • 1

    +1 for the citation of pointer 0 in memory = D

  • 1

    +1 - perfect technical description.

  • 1

    I remember two C++ programmers discussing what the value at the 0 position of memory... even entered into the merit of whether the capacitor was loaded or not. I don’t know the answer, not electronics. P

  • @Onosendai is far from perfect. Even I know that you can improve a lot. And it is not so well designed :)

  • @Bigown perfection, as well as beauty, is in the eye of the beholder. = ) It is synthetic and going to the point.

Show 3 more comments

11

On the website of Macoratti, it defines NULL as follows:

Null A value that indicates missing or unknown data in a field. You can use Null values in expressions. Null values can be entered into fields of which information is unknown, thus as in expressions and queries.

In my conception it is a type of data that is not empty and is not zero, for me it is an unfilled information, or rather, undefined.

8

Null is basically no value.

Ex:

public $variavel = 0; //não é nulo!

public $variavel; // é nulo

5

NULL means null, worthless. Imagine, for example, an optional balance property accepting any real number. If optional, there is no number to be assigned that indicates that there is no assigned balance, as 0, positive and negative values are valid balance values. Assign NULL indicates that there is no value assigned. It is simply a representation of no value.

4

NULL, NIHIL, N/C - all this means null, unanswered, blank.

The special value NULL represents that the variable has no value. NULL is the only possible value of the type NULL.

Null is the ASCII character "00", is the value of a variable that has not yet been initialized

  • 2

    Even though it’s just quotes, I don’t understand what’s wrong with this answer, it would be nice to have a negative opinion.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.