rewording algorithms

A few months ago, my main impression of the algorithms was that they
were needlessly complex; it wasn't until this weekend that I figured
out why.

Some of them are phrased to avoid an early exit.  This is useful in
programming languages when you need to clean up, but is more difficult
for humans to understand.  (~10 years ago, the most accessible
literature was in linguistics, and dealt with center-embedding.)

To make this more concrete, the wording for the optgroup namedItem
method is good; the end of each step is effectively either "stop,
you're done", or "forget this step; it didn't work; go to the next."

http://www.whatwg.org/specs/web-apps/current-work/#nameditem1

In contrast, the method for determining a script's type seems to read backwards:

http://www.whatwg.org/specs/web-apps/current-work/#running0

The only way I could understand it was to reword it mentally, and then
it looked incomplete.  I would reword it to similarly to whichever of
the following is intended:

If the script element has a type attribute, this determines the Script's Type.
    If the type attribute's value is the empty string, then the
Script's Type is "text/javascript".
    Otherwise, the Script's Type is the value of the type attribute.

Otherwise, if the script element has a language attribute, this will
determine the Script's Type.
    If the value is the empty string, then the Script's Type is
"text/javascript".
    Otherwise, the Script's Type is "text/" + the value of the
language attribute.

Otherwise (if the script has neither a type attribute nor a language attribute):
    ?  Assume "text/javascript" or raise an Error?

-jJ

Received on Tuesday, 7 August 2007 15:00:56 UTC