W3C home > Mailing lists > Public > public-webapi@w3.org > March 2008

Re: [Element Traversal LC] access to element by index

From: Doug Schepers <schepers@w3.org>
Date: Fri, 28 Mar 2008 15:38:24 -0400
Message-ID: <47ED4930.3090806@w3.org>
To: Boris Zbarsky <bzbarsky@MIT.EDU>, "Web APIs WG (public)" <public-webapi@w3.org>, Daniel Glazman <daniel.glazman@disruptive-innovations.com>

Hi, Boris-

Boris Zbarsky wrote (on 3/28/08 1:41 PM):
> Doug Schepers wrote:
>>  Speaking as an author of many SVG Webapps and a contributor to 
>> several SVG script libs, knowing the number of child elements is a 
>> really common need; index-based access is less needed, and can be 
>> effected by other means.
> I would just like to point out, from my perspective as an implementor, 
> that implementing this as a nodelist would have taken all of 15 minutes 
> of programming time.  Implementing the specification as written, while 
> having acceptable performance on traversal, will take a good bit more 
> work, and either a lot more complexity or additional space used by every 
> single Element in the DOM.
> I realize that this is due to the fact that I'm working with an 
> implementation that already has a generic NodeList implementation... 
> Nevertheless, the issue is there.
> I have the feeling that I already mentioned this in the past, so I 
> assume it's been considered in making the decision that the 
> linked-list-only API is the one to use, but I wanted to mention it in 
> case I hadn't before.

Yes, you did, and I pointed out that not all implementations have 
existing nodeList implementations, and that one of the design goals was 
to work with mobile UAs that don't already support nodeList (live or 
static). [1]

After some discussion in the same thread, I then put the direct question 
to the list as to whether or not to include a nodeList [2], and the only 
reply I got was from Maciej, in support of removing it. [3]

This was last April, and the spec has not changed appreciably since 
then, so I assumed the issue was closed, and that you appreciated the 
design goal.

> P.S.  Oddly enough, in typical DOM authoring authors use index-based of 
> childNodes a _lot_ more than the linked-list accessors....  Has anyone 
> looked into why?

My guess is that undifferentiated navigation to any node type is simply 
not that useful, which is why Element Traversal was made.  Also, without 
knowing the number of child nodes of the target type, there are some 
pre-processing operations that aren't easily done, so again it's less 
useful; by the time you bother getting a nodeList to find out the number 
of children, you may as well iterate through the list.

Also, it may be that casual authors simply don't know about those 
accessors, since looping structures are themselves so widely used.

[1] http://lists.w3.org/Archives/Public/public-webapi/2007Apr/0009.html
[2] http://lists.w3.org/Archives/Public/public-webapi/2007Apr/0012.html
[3] http://lists.w3.org/Archives/Public/public-webapi/2007Apr/0013.html

-Doug Schepers
W3C Team Contact, SVG, CDF, and WebAPI
Received on Friday, 28 March 2008 19:38:58 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:16:25 UTC