W3C home > Mailing lists > Public > whatwg@whatwg.org > May 2012

[whatwg] DOMTokenList methods would be more useful with a space separated token list

From: Rick Waldron <waldron.rick@gmail.com>
Date: Wed, 2 May 2012 21:01:26 -0400
Message-ID: <CAHfnhfrh6zUrjDj-UdHpTUPBTZPNhwZAjNYnDN7go-PGh3bXxw@mail.gmail.com>
On Wed, May 2, 2012 at 7:17 PM, Ian Hickson <ian at hixie.ch> wrote:

> On Wed, 2 May 2012, Rick Waldron wrote:
> >
> > JS APIs like this should always return the object (constructed instance
> > or not) and therefore chain implicitly.

Let me rephrase, I simply expect modern DOM APIs to return something useful.

> I understand that this is mostly a matter of taste in API design, but IMHO
> that's an anti-pattern.

If you're writing and designing specifications that will be implemented in
JavaScript, then you should design them _for_ JavaScript. Section 15 of
EcmaScript specifies more then enough "prior art" that supports my
statement above.

> It encourages poor style;

60% of the JavaScript written on the web disagrees.

> it discourages
> functional programming patterns, instead favouring state mutation
> patterns;

JavaScript is a multi-paradigm language, leave your design hangups at the

it makes APIs harder to extend;

This is just outright false, considering JavaScript is probably the most
extendable and historically extended language at the API level.

> it makes APIs that do have
> useful return values inconsistent with other APIs;

elem.classList.add("foo") returns "undefined". That's hardly what I would
consider a "useful return value". Returning the element's classList
instance makes an incredible amount of rational sense.

> it is, in fact, a
> layering violation:

it attempts to shoehorn what should be a language

design feature into the API layer.

Much like the DOM and its weird C++ and Java influences.

> But I'll leave it up to the DOM guys to decide what to do for that
> interface. :-)

Is this group aiming to define APIs that developers will always paper over
with abstractions, guaranteeing all app code needs a good 50k just to
provide a decent API? Or shall we craft APIs that developers will actually
write code for?


> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 2 May 2012 18:01:26 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:41 UTC