Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Also, null might be the empty string, but when is it ever zero?

Edit: this is a serious question.



A language that truly supports null has monadic types, meaning that typed value (scalar, string, object, etc) or something else is specifically tracked (null, undefined, etc). Languages that do not natively support that often have developers that cheat, where they assign some particular value to represent null. Commonly, this is 0 or -1 in numbers and an empty or literal "null" in strings. This works fine unless these values appear actually as legitimate values.


Lately, I program in a language that has distinct concepts of Null and Empty and Nothing and the empty string ("") and arrays that are not Empty but contain zero elements. And of course NUL characters.

This is obviously at least five times as good as just having one option for null.


> arrays that are not Empty but contain zero elements

What is an array that is not empty but contains zero elements?


Well, Empty is a special value in VBA. And I forgot to mention, there are two kinds of "empty" arrays that are not Empty. So it's six times as good as a normal language.

Here's an example:

    ' x can be anything, including an array, but
    ' defaults to the value Empty.
    Dim x

    ' y is an array of values that can be anything,
    ' which defaults to an empty array.
    Dim y()
    
    ' Initialize x as an empty array
    x = Array()
    
    ' The following two statements print 0 and -1.
    Debug.Print LBound(x)
    Debug.Print UBound(x)
    
    ' The following two statements error with
    ' "Subscript out of range" even though y
    ' is also a kind of empty array.
    Debug.Print LBound(y)
    Debug.Print UBound(y)


IIRC in Visual Basic these are arrays with lower bound bigger than upper bound.


...but sometimes you can observe this and sometimes you can't.


Sounds like a trick question. How about the array of the largest number?


Which language?


You can look at headers:

#define NULL 0 //C++

#define NULL ((void*)0) //C

I think later versions of C++ do something...different, but I’m not up to date enough to know without looking it up.


Ok, I wasn't thinking of C, but even so, isn't NULL a pointer value, not an integer? If you're treating a null pointer as an integer zero, something's gone very wrong.

Also I think I vaguely remember from discussions about the standards, that a NULL pointer is not guaranteed to be numerically equal to zero in a standards compliant compiler.

But yeah, I was thinking of database NULLs.


C++03 and earlier stipulate that literal 0 is always the null pointer, whether it really is on any given hardware or not. C++11 and later deprecate this and introduce a new keyword `nullptr`.

edit: Also, null is not an empty string. The null character that terminates a string is unrelated to null pointers.


Normally I call it the NUL character to distinguish it.


In Oracle SQL, an empty string is equivalent to a null, as I recall. However, that is not true for all databases.


Man, this is one of those discussions I’d like to drag out for a little bit, but unfortunately not in a position to do so. I will leave you with the idea that null can indeed be a value, as in a null-terminated string. Go look at that guy in memory.


If you're going to split hairs, I'm going to say a NUL character is obviously not the same concept as a NULL in general, nor is it a number that you'd use for a coordinate.


The definition of NULL is technically machine-dependent in C. It happens to be 0 on (almost?) every machine, but that's not guaranteed. In C++ it's guaranteed to be 0.


The times where it wasn't zero are interesting, https://stackoverflow.com/questions/2597142/when-was-the-nul...


"May you live in interesting times!"


It's a fair point.

Null is the absence of a value. When used in a programming context it is either a pointer (which is not an integer or a float -- it's the pointer to the absence of an integer or a float. It is not equivalent to 0 or 0.0 or ""), a magic number (specifically for chars), or a special structure with a flag.

This more correctly would be "Default=0 Island". A database that doesn't have a nullable field would be the one where you'd have 0.0 as the defaults.


>It's a fair point.

Pun.


When it's a pointer.

Remember, a pointer contains the actual address in RAM, or 0 when the pointer is null.


Usually, but not always.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: