Re: [whatwg] WebIDL and HTML5

On Wed, Aug 27, 2008 at 5:13 PM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Garrett Smith wrote:
>>
>> Java does not include null value for String type. You can ignore the
>> null type and just pretend that null can be of any reference type, but
>> that does not make null a string.
>
> Any Java method that takes a String can have null passed to it.

Yes, and this is true for any reference type, not only String.

> That's the
> only question here: if the method says it takes a DOMString, what can you
> pass to it?
>

Are you concerned with what can be passed to a method, or what is a String?

In EcmaScript, well, didn't we have a demo here just a few hours ago?
I included four primitives in the demo: null, undefined, number,
string. I forgot boolean. Not only can you pass anything, it mostly
"works", with the exception of null and (for IE) undefined. Should it
work for null? I would say for consistency, it should probably work.
However, if a method takes a domstring, why would anyone want to pass
null?

Passing null where a domstring is required has been demonstrated to
result in behavior that is inconsistent with the way the same method
converts other primitive values. It works inconsistently across
browsers, cause problems, and relies on bad parts of the spec.
Wouldn't passing null seem to be a mistake? Just don't do it!

In Java, you're more limited. You can pass a float to a method that
takes a Double, promote a char to an int, pass a subclass to a method
that accepts an interface. There's boxing/unboxing. I can't remember
all of what is

Null is not a String. Not in Java; not in EcmaScript. In both
languages, the Null type has no Name and has only one value - null.

EcmaScript:
  if(s) { .. }

Java:
  if(s != null && !s.equals("")) { ... }

Java's null is not a string.

In Java, all Variables have a type. Reference Variables can have the
value null and this special case often requires special handling.

EcmaScript's null is not a String. It is a primitive value.

Unlike Java, EcmaScript offers no compiler checks for *anything*.
Variables are not typed, values are. In EcmaScript, you can pass
anything to anything.

JSL 3rd Edition, Types, Values, and Variables:
http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html

Garrett

> -Boris
>
>

Received on Thursday, 28 August 2008 07:01:30 UTC