W3C home > Mailing lists > Public > public-html@w3.org > November 2009

Re: Namespace-aware APIs do not need to suck

From: Julian Reschke <julian.reschke@gmx.de>
Date: Thu, 05 Nov 2009 15:40:48 +0100
Cc: public-html@w3.org
Message-ID: <20091105144048.46310@gmx.net>
To: Maciej Stachowiak <mjs@apple.com>
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

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:45:02 UTC