Comments (12)
Yeah, I think "continue" is pretty much a loop thing in every language I'm aware of; using it outside loop contexts seems pretty confusing to me.
from infra.
If we could use "continue" in arbitrary nested steps, that would address the "abort these substeps" case (means hand to the parent). And use "return" for the other scenario.
from infra.
The problem with using "return" in that context is for when you have async stuff going and want to write something like:
1. Do sync stuff.
1. Return and run the following sub-steps [=in parallel=]:
1. Do async stuff.
1. More async stuff.
from infra.
This is a tricky area and I'm not sure there are any great answers :-/. A few thoughts that have run through my mind:
My main problem with @annevk's preferred "abort these subnsteps" is that you never know if a spec is using it or not. So if you see:
1. Do X
1. If y, then:
1. Do y1
2. If z, then:
1. Do z1
2. If q, abort these steps.
1. Do R
Then "abort these steps" is ambiguous:
- It could be authored by someone like @annevk who uses the "abort these subnsteps" convention. In that case, "steps" refers to the entire algorithm, so the entire algorithm gets aborted, and "Do R" does not happen.
- It could be authored by someone else who doesn't use that convention. (For example, most of HTML, I believe.) In that case "steps" probably only refers to the current set of subsubsteps, so only the current set of subsubsteps gets aborted, and "Do R" happens.
Another issue with "abort these subnsteps" is that I don't believe it has any counterpart in most programming languages. (Besides maybe factoring things out into a smaller function and using return
).
I have never liked the "Return and run the following sub-steps [=in parallel=]" construct, despite its prevalence across many specs. Precisely because in most programming languages it's impossible to do something after returning. Maybe we could ban that in Infra-using specs? Meh, that would invalidate much of HTML, which uses it a lot.
In general the things that are unambiguous are:
- "Abort this algorithm"
- "Jump to the step labeled x".
Maybe we should strive to only use those things? (Plus return and throw.)
from infra.
@domenic you didn't mention "continue". I guess you don't want to use that outside contexts where JavaScript uses it?
from infra.
Maybe labeled substeps, a'la Java:
- Do X
- Foo: If y, then:
- Do y1
- If z, then:
- Do z1
- If q, abort the Foo substeps.
- Do R
from infra.
More thoughts and some questions:
I'm not a big fan of subNsteps either. The question is how would we rewrite those algorithms today? (I looked through DOM and it doesn't really need that convention at all, so it would be trivial to get rid of there at least. Just need to do it and someone to review it.)
I tend to agree that return and run is rather sad and run in parallel and then return would work better. (Soft-)banning that in Infra seems acceptable, since much of HTML doesn't conform to all the rules we write down here.
Using return from in parallel steps seems fine to me as well, it'll just terminate those steps and that's it. (But then again, I don't quite like in parallel to begin with and I think we can do better.)
I think we should strongly consider labeled steps. URL has them, DOM has them, I think HTML has them in a few places. They're a little ugly, especially "jump to", but also fairly readable. Thoughts?
from infra.
Using return from in parallel steps seems fine to me as well, it'll just terminate those steps and that's it. (But then again, I don't quite like in parallel to begin with and I think we can do better.)
I think that'd be confusing if used within the context of a larger algorithm; are you returning from the algorithm or from the in-parallel substeps? @jyasskin's #56 (comment) idea might be the best we have there.
I think we should strongly consider labeled steps. URL has them, DOM has them, I think HTML has them in a few places. They're a little ugly, especially "jump to", but also fairly readable. Thoughts?
In general I like them. I guess the trick is to not overuse them when break or continue would do.
There is the whole "goto considered harmful" business though, and I wonder if we have any good arguments for why that might apply less to specs.
It'd be good to make these decisions with some more cases in mind. E.g. pick 3-6 algorithms from various specs and analyze how we'd ideally write them.
from infra.
@domenic and I discussed labels a bit more on IRC. Given http://www.u.arizona.edu/~rubinson/copyright_violations/Go_To_Considered_Harmful.html and the ability for standards to refactor we're somewhat less inclined to add it. Figuring out how to rewrite existing usage is still important of course.
We also thought that perhaps standards use functions less is because other standards might use them as hooks, so being able to distinguish between public and private API more clearly was seen as something nice potentially. (And in terms of the Bikeshed dfn protocol, there's some need to export private functions sometimes. For monkey patching and explaining the interweaving of standards (e.g., CSP and Fetch).)
from infra.
2 things:
- Breaking from a labeled level of a control structure is different from arbitrary gotos. I mentioned Java on purpose, since it omitted arbitrary gotos.
- Refactoring a function that's only used once out of an algorithm can make that algorithm harder to understand. Not always, of course, but I think we should let editors and spec reviewers use their judgement instead of saying that you can only express certain things by factoring out a helper function.
from infra.
Another issue with "abort these subnsteps" is that I don't believe it has any counterpart in most programming languages.
Nit: a number of languages have labeled or numbered break
statements, that can break out of multiple nested constructs at once.
from infra.
Concluding this thread:
- Labeled steps is now #119.
- In parallel is #120.
- We'll continue to remove "substeps" from existing algorithms. Feel free to file bugs when you come across instances. (I already cleaned up a bit in DOM/URL/HTML.)
from infra.
Related Issues (20)
- Clarify USV handling in "serialize a JavaScript value to JSON bytes" HOT 1
- Consider defining "failure" HOT 2
- Expand on list indexing syntax
- Conditional abort edge case HOT 2
- Forgiving base64 HOT 8
- "do while" loops HOT 5
- Iteration and append methods for byte sequence used in standards are undefined HOT 1
- Skipping an item while iterating is undefined HOT 1
- Define monkeypatching HOT 3
- Consider defining "unique internal value"
- Explicit unions HOT 1
- definitions of "Continue" and "Break" should be clear that they apply to the innermost loop
- Define ordering for sets and maps? HOT 4
- Define remainder (and/or modulo) HOT 2
- Peek operation for stacks
- "Parse JSON to Infra" algorithms shouldn't require a current JS realm HOT 4
- Define set difference
- Give some examples of how to use structs
- Add a clone method for struct
- tracking/icon for features that might expose use of accessibility tools HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from infra.