You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by Sven Helmberger <sv...@gmx.de> on 2009/01/08 14:21:27 UTC
null
Hi!
When I was writing jcouchdb, I came across the fact that it seemed to
make difference whether the _rev field just wasn't there or if it was
null, something that made me wonder.
The problem for me was solved with the "ignoreIfNull" feature in
jcouchdb, but I'd like to ask the question in general:
Shouldn't couchdb treat null and undefined values the same?
I am aware that there is in fact a difference in javascript, but since
there is no "undefined" keyword for JSON, I would argue that that should
not be the case for JSON and couchdb.
Sven Helmberger
Re: null
Posted by Christopher Lenz <cm...@gmx.de>.
On 08.01.2009, at 15:01, Christopher Lenz wrote:
>> The absence of an "undefined" keyword leads me to the expectation
>> that for JSON {} should be the same as {"foo":null}.
>
> No, "undefined" means that an object has no such property, whereas
> {"foo":null} clearly *has* a "foo" property.
>
> I'm not sure what problem you're trying to solve here. If you need
> to state that a JSON object doesn't have a property, simply omit it.
> No need for an invalid keyword.
s/invalid/undefined
Cheers,
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/
Re: null
Posted by Sven Helmberger <sv...@gmx.de>.
Christopher Lenz schrieb:
> If you need to
> state that a JSON object doesn't have a property, simply omit it. No
> need for an undefined keyword.
>
> Also note that "undefined" is not a keyword in Javascript either, it's the
> string value returned by `typeof somethingUndefined`.
>
ECMA-262 defines undefined as:
4.3.9 Undefined Value
The undefined value is a primitive value used when a variable has not
been assigned a value.
4.3.10 Undefined Type
The type Undefined has exactly one value, called undefined.
it's not just a name. Try this in a javascript console:
var foo; alert( foo === undefined);
undefined is a special value of a builtin Type, just like true, false or
null.
> I'm not sure what problem you're trying to solve here.
It's easier in some languages / situtations to be able to substitute
null, meaning no revision. In my case the problem was solvable with an
additional annotation attribute, it might be more difficult in other
situations.
I'm not saying that this is a real problem. I was just wondering what
the omission of undefined (and other special values like NaN) means for
JSON and applications using it. And I thought I just mention it here.
Sven Helmberger
Re: null
Posted by Christopher Lenz <cm...@gmx.de>.
On 08.01.2009, at 14:37, Sven Helmberger wrote:
> Noah Slater schrieb:
>> On Thu, Jan 08, 2009 at 02:21:27PM +0100, Sven Helmberger wrote:
>>> Shouldn't couchdb treat null and undefined values the same?
>> Well, a "null" value is a way of saying "this doesn't have a value"
>> but when
>> something is undefined, you don't know if it has a value or not.
>> The difference
>> is subtle, but it's an important one.
>>> I am aware that there is in fact a difference in javascript, but
>>> since
>>> there is no "undefined" keyword for JSON, I would argue that that
>>> should
>>> not be the case for JSON and couchdb.
>> Well, an undefined value is by definition, undefined.
>
> in javascript, "undefined" is a keyword for an undefined value.
> exactly the value that doc._rev has when doc has no property _rev.
Technically, and nitpickingly, that's not the value doc._rev has,
because doc._rev does not exist ;) It's the value returned by
Javascript when you access a property that doesn't exist.
> The absence of an "undefined" keyword leads me to the expectation
> that for JSON {} should be the same as {"foo":null}.
No, "undefined" means that an object has no such property, whereas
{"foo":null} clearly *has* a "foo" property.
I'm not sure what problem you're trying to solve here. If you need to
state that a JSON object doesn't have a property, simply omit it. No
need for an invalid keyword.
Also note that "invalid" is not a keyword in Javascript either, it's
the string value returned by `typeof somethingUndefined`.
Cheers,
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/
Re: null
Posted by Sven Helmberger <sv...@gmx.de>.
Noah Slater schrieb:
> On Thu, Jan 08, 2009 at 02:21:27PM +0100, Sven Helmberger wrote:
>> Shouldn't couchdb treat null and undefined values the same?
>
> Well, a "null" value is a way of saying "this doesn't have a value" but when
> something is undefined, you don't know if it has a value or not. The difference
> is subtle, but it's an important one.
>
>> I am aware that there is in fact a difference in javascript, but since
>> there is no "undefined" keyword for JSON, I would argue that that should
>> not be the case for JSON and couchdb.
>
> Well, an undefined value is by definition, undefined.
>
in javascript, "undefined" is a keyword for an undefined value. exactly
the value that doc._rev has when doc has no property _rev.
The absence of an "undefined" keyword leads me to the expectation that
for JSON {} should be the same as {"foo":null}.
Re: null
Posted by Noah Slater <ns...@apache.org>.
On Thu, Jan 08, 2009 at 02:21:27PM +0100, Sven Helmberger wrote:
> Shouldn't couchdb treat null and undefined values the same?
Well, a "null" value is a way of saying "this doesn't have a value" but when
something is undefined, you don't know if it has a value or not. The difference
is subtle, but it's an important one.
> I am aware that there is in fact a difference in javascript, but since
> there is no "undefined" keyword for JSON, I would argue that that should
> not be the case for JSON and couchdb.
Well, an undefined value is by definition, undefined.
--
Noah Slater, http://tumbolia.org/nslater