Re: Alternate syntax for defining class attribute

Hi Ian,

Thanks for the considered answer.

> We've looked at doing this before, but it has a very poor backwards-
> compatibility story, unfortunately.

Yes, again, I did make the point in my original post that using this
shorthand form would very much be a "caveat author" (author beware)
situation -- the effect in older UAs will not be as desired.  Very
much like the new tags.  I frankly wouldn't expect to get much use out
of this new shorthand form for a good 3-4 years while compliance comes
up -- but in 3-4 years, it would be quite nice to have, hence
suggesting it now.

> I would encourage you to find ways to avoid using class attributes, e.g.
> by writing selectors that are based on the structure of the document.

Yes, naturally one does that wherever possible.  In the real,
pragmatic world of interactive web applications, it's simply not
always possible, and sometimes not preferred for other reasons.

> It wouldn't be that hard to parse, but it would only say you a 5
> keystrokes...

Which is to say, frequently, half the total.  I think 50% gains are
worth pursuing.  But even more so, the alignment with CSS syntax is
very attractive and natural.

-- T.J.

2009/8/15 Ian Hickson <ian@hixie.ch>
>
> On Sun, 9 Aug 2009, T.J. Crowder wrote:
> >
> > First off, thank you for all of your work hammering out HTML5. Greatly
> > appreciated!
>
> Thanks!
>
>
> > I have a suggestion which may be too late for HTML5 or not in keeping
> > with the philosophy, but I'll give it a go:
> >
> > We use the class attribute a *lot*.  To save our poor fingers, not to
> > mention reduce document sizes, would it be possible to introduce an
> > alternate syntax for simple situations (one class) mirroring the basic
> > CSS class selector syntax?  E.g., this:
> >
> >     <div class='nifty'>nifty stuff here</div>
> >
> > becomes
> >
> >     <div.nifty>nifty stuff here</div>
> >
> > Seems to me this is easily parsed and not a significant burden to
> > implementors, whereas I think most authors would be thrilled to have the
> > syntax line up with CSS and to stop typing "class='" all over the place.
>
> We've looked at doing this before, but it has a very poor backwards-
> compatibility story, unfortunately.
>
> I would encourage you to find ways to avoid using class attributes, e.g.
> by writing selectors that are based on the structure of the document. For
> example, instead of:
>
>   <h1>...</h1>
>   <p class="firstp">...</p>
>
>   p.firstp { ... }
>
> ...do something like:
>
>   <h1>...</h1>
>   <p>...</p>
>
>   h1 + p { ... }
>
>
> > Alternatively (no pun), a less easily-parsed version that doesn't seem
> > to break the small number of UAs I tried (all browsers: IE7, FF3,
> > Safari3win, Opera9, Chrome2) too badly is to allow whitespace between
> > the tag and the dot:
> >
> >     <div .nifty>nifty stuff here</div>
> >
> > Older browsers wouldn't see the class name, obviously, but they seem to
> > mostly ignore the invalid attribute.  I don't like this becaue it looks
> > like a parsing nightmare to me, although as I said, I'm not a parser
> > guy.
>
> It wouldn't be that hard to parse, but it would only say you a 5
> keystrokes, and all the old browsers would miss the class attribute, so
> it's not really worth it, I think.
>
> Cheers,
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Saturday, 15 August 2009 12:57:40 UTC