Lambda the Ultimate

inactiveTopic Javascript with native XML support
started 4/1/2003; 11:42:34 PM - last post 4/3/2003; 3:08:56 AM
Dan Shappir - Javascript with native XML support  blueArrow
4/1/2003; 11:42:34 PM (reads: 1968, responses: 7)
Javascript with native XML support
From the LtU Discussion Group:

Somebody pinch me and don't tell me this is an April Fool's joke. This is absolutely what I have been hankering for. JavaScript gets native XML support (E4X). It has already been adopted by BEA.

Additional information can be found here.
Posted to xml by Dan Shappir on 4/1/03; 11:42:57 PM

Dan Shappir - Re: Javascript with native XML support  blueArrow
4/1/2003; 11:57:26 PM (reads: 1119, responses: 1)
This development was already discussed on LtU.

As you can see, it's not surprising that BEA supports it as seems that it's BEA that instigated it. If you recall the XML programming discussion, you will see that Tim Bray links to an article by Adam Bosworth Vice President of Engineering at BEA in hints at this development.

Ehud Lamm - Re: Javascript with native XML support  blueArrow
4/2/2003; 12:16:34 AM (reads: 1166, responses: 0)
Indeed. But is there a complete reference/tutorial out there?

Keith Devens - Re: Javascript with native XML support  blueArrow
4/2/2003; 1:45:44 PM (reads: 1055, responses: 4)
This is the only documentation I know of.

Dan Shappir - Re: Javascript with native XML support  blueArrow
4/3/2003; 12:18:14 AM (reads: 1059, responses: 3)
Scanning this documentation I can only reiterate my concerns with the various semantic tweaks they have done to ECMAScript in order to get this to work.

Indeed, I can add several new concerns:

1. Various partial workarounds (hacks) to handle scenarios where XML node names conflict with reserved words or member functions.

2. Changing the semantics of the for...in statements - for standard ECMAScript objects it iterates over the indices, for XML it iterates over the values.

3. Lots of new operators and new ways to bunch operators together.

4. Yet another overload for {...} (ECMAScript already uses it for 2 distinct purposes).

5. += and + used to combine XML, but delete and not - or -= is used to remove elements.

As I stated in the past, I like seeing ECMAScript extended with new functionality. OTOH such additions should be done in a way that is consistent with the feel of the language. IMO BEA (like Microsoft with JScript.NET before them) have crossed that line a bit.

Ehud Lamm - Re: Javascript with native XML support  blueArrow
4/3/2003; 12:24:18 AM (reads: 1099, responses: 2)
Were there any serious alternative?

Dan Shappir - Re: Javascript with native XML support  blueArrow
4/3/2003; 2:06:30 AM (reads: 1155, responses: 1)
Were there any serious alternative?

I'm not sure what you mean by serious. If you mean changes to ECMAScript that would have made XML programming as simple, then I think it's a bit of a loaded question. Once such changes are introduced into the language they affect everything, not just XML programming. So if a change makes XML handling easier but has the downside of making the language specification more fragile, is that a good thing? E4X was intentially not done as a library so you can't just take it or leave it. Being a language extension you must always take it, whether or not you intend to use it.

Actually I'm not quit sure about that. It could be that you will have some sort of compiler switch to activate the E4X extensions. If that is the case then (like JScript.NET /fast switch) I'm not sure the cure isn't worse than the disease.

Other objections I have are fixable IMO. They have made some design decisions, that while logical in themselves, create unwarranted distinctions between standard ECMAScript objects and XML objects. For example, the implementation of for...in and support for the .. operator. As a result, identical code will behave differently if an XML object is passed as parameter or any other type of object.

I also think ECMA could have provided language extensions which would have allowed application of some of these features in other contexts. Want to support += for adding items to an XML list? fine, but allow me to use += for my lists as well, i.e. operator overloading. Currently ECMAScript doesn't even support += on intrinsic arrays.

Finally, adding lots of operators makes expressions shorter, which certainly makes it look cooler during a demo. But in the long term, I'm not a big fan of Perl-style syntax. I prefer to have to write a bit more and make code more readable.

Oh yes, one other thing. They totally ignored ECMAScript's functional capabilities. Even when they made perfect sense, such as filtering with Predicates.

Ehud Lamm - Re: Javascript with native XML support  blueArrow
4/3/2003; 3:08:56 AM (reads: 1195, responses: 0)
I also think ECMA could have provided language extensions which would have allowed application of some of these features in other contexts.

That's basically what I wanted to ask. Were such extensions suggested and discussed?