New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefer explicit algorithmic steps and constructs #10
Comments
Yes! (Though for CSS specifications this might not always be desirable I believe. @dbaron and @tabatkins might have more to say.) |
Be careful of not imposing a mono-thread version of an algorithm that could otherwise be MT, as this might be harmful in the long run. |
Yeah, we should probably also be cautious of any new synchronous APIs. |
Nah, I mostly agree. Exactly how "algorithmic" is appropriate is up for debate, of course. (Compare Grid's current sizing algorithm which is explicit but readable, with the previous one which is barely-translated C++ code.) |
I think there are certainly contexts where advice to prefer algorithm steps could be interpreted in a way that produces bad results. The primary example I'm thinking of is the CSS syntax specification. Tab's early drafts of the spec were very algorithmic, and depended on the spec author manually maintaining invariants like brace-matching. It was in an algorithmic form that meant that a hard-to-detect spec error could break an invariant that we wanted to maintain perfectly (because we use these invariants to allow future extensions). I encouraged Tab to specify the invariants more directly, which simplified the specification, and made it much much harder for both spec authors and implementors who closely follow the specification to make those errors. |
Another area of concern is that there are cases where the spec author could choose multiple algorithms that produce equivalent results. However, later changes to the spec, or edge cases that the author hadn't thought of, might end up making it so that the different algorithms are no longer equivalent, and in order to be conformant, an implementation would effectively need to implement in the form that was in the spec. (I remember arguing with Tab about such an algorithm, which I suspect was in a selectors draft, although I've forgotten exactly what.) So it actually matters which algorithm is chosen, and it's absolutely not a purely editorial issue, because it may well end up being the way implementations have to implement it. |
It seems generally useful to have well-written algorithmic constructs to show how things are meant to work. It also seems valuable to describe what is meant to happen in a non-algorithmic way, not least for people who just want know if the API does what they think when they are deciding whether and how to use the API, |
And one other point that just came up at today's TAG meeting: algorithms in specs should, like code, be understandable and reviewable. I've seen algorithms in specs that were clear and understandable, and I've seen some that where spaghetti code with weird side-effects across chapters. |
+1 - and more generally, writing well makes a serious difference (whether it is algorithm, code, or prose). |
Syntax is still completely algorithmic. It just changed from being a state machine to a recursive-descent parser, which dramatically simplified tokenizing (you can reuse sub-algos when you can easily return to where you left off) and made the parser part easier as well. So this is just a matter of writing a good algorithm.
It was about whether the selector match algorithm should be specified as using a selector left-to-right or right-to-left. Some selectors are easier to describe ltr, but browsers all implement them rtl. |
…more readable formal concepts that decompose to them. This also expands the section on specification writing advice to include a substantive section, rather than being only links to other resources. Fixes w3ctag#10.
Typo fix: use `ctx` in both places within the example.
For an example, see the before-and-after on Web Audio's
OfflineAudioContext.prototype.startRendering
:before
after
Some points of note:
The text was updated successfully, but these errors were encountered: