Re: Namespace-aware APIs do not need to suck

Maciej wrote:
> So you could imagine code like this:
> 
> var el1 = document.createElementNS2("{http://www.w3.org/1999/ 
> xhtml/}span");
> var el2 = document.getElementsByTagNameNS2("{http://www.w3.org/1999/xhtml/
> }div")[0];
> el2.appendChild(el1);

Yes. As a matter of fact, this *could* be just createElement, as the curly braces allow to detect the new format of the argument reliably.
 
> Hmm. The fact that you have a single identifier instead of a tuple  
> sucks less. But it seems to me the resulting code is not very easy to  
> read, or pleasant to write. You could put the bracey bit in a variable  
> like people do with namespace URIs today:
> 
> var xhtmlNS = "{http://www.w3.org/1999/xhtml/}";
> var el1 = document.createElementNS2(xhtmlNS + "span");
> var el2 = document.getElementsByTagNameNS2(xhtmlNS + "div")[0];
> el2.appendChild(el1);
> 
> But then all you've really done is replace a comma with a plus. I'm  
> not convinced that this will aid author understanding.

Guess what? I wouldn't expect that either.

Of course the assumption is that people would declare the whole expanded name once:

var nspan = "{http://www.w3.org/1999/xhtml/}span";

var el1 = document.createElementNS2(nspan);

> Furthermore, what you're writing still doesn't match the markup, which  
> uses prefixes instead of Clark notation. Thus I think content  
> producers and consumers will continue to mistakenly think the qname is  
> the semantic unit, instead of the Clark-style namespace+URI string.

And it's not supposed to match the markup for that very reason.

The proposal addresses the point Jonas made (that passing in tuples is ugly). That's it.

BR, Julian

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01

Received on Thursday, 5 November 2009 14:41:25 UTC