This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26660 - Use nested lists for loop "blocks" in table-sorting-algorithm
Summary: Use nested lists for loop "blocks" in table-sorting-algorithm
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-25 23:12 UTC by contributor
Modified: 2014-09-17 22:58 UTC (History)
3 users (show)

See Also:


Attachments

Description contributor 2014-08-25 23:12:01 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html
Multipage: http://www.whatwg.org/C#table-sorting-model
Complete: http://www.whatwg.org/c#table-sorting-model
Referrer: 

Comment:
Use nested lists for loop "blocks" in table-sorting-algorithm

Posted from: 99.237.75.191
User agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36
Comment 1 caitp 2014-08-25 23:13:55 UTC
As you might imagine, I started working on a patch for this feature in Blink, and the actual sorting algorithm is the big chunk, quite an eyeful of instructions! It also contains a number of what I would consider "block scope" kind of constructs, and these would be much, much easier to read if they were formatted as nested lists.
Comment 2 Ian 'Hixie' Hickson 2014-08-26 17:59:41 UTC
How would you phrase the steps that currently say "jump to the step labeled end below" if the "end" step wasn't in the same set of steps?
Comment 3 caitp 2014-08-26 18:40:47 UTC
For example (does not go all the way to the end, because it's a rather long set of steps, but hey): https://gist.github.com/caitp/71a97bcb41fdb145b688

The prose used feels much more turing-complete and better suits the description of computer programmes --- but on top of that, it's much easier to visualize what should be happening. Replacing labeled steps with these constructs is much easier to read and comprehend (in my opinion).
Comment 4 Ian 'Hixie' Hickson 2014-08-27 21:47:30 UTC
"Repeat while row collection cursor is not null" doesn't work because if I ever add a step after the one that mutates "row collection cursor", it won't be clear what that means any more.

But anyway, I guess your answer to comment 2 is just "leave them as is", i.e. you're fine with gotos that cross loop scopes. Is that right?
Comment 5 caitp 2014-08-27 21:59:35 UTC
"doesn't work because if I ever add a step after the one that mutates "row collection cursor", it won't be clear what that means any more."

Can you explain how it would not be clear anymore? The idea is, there are patterns that we use repeatedly (evaluate different lists of steps conditionally, depending on different inputs, repeat a set of  steps until a terminating condition). It's the same pattern no matter how it's written, but writing it this way makes it much easier to identify the pattern at a glance, without having to digaround for terminating conditions.

But yes, the formatting of the lists is much more important. Even with the labels everywhere, it's still much easier to understand when "scopes" are indented and formatted as children of the parent "scope".
Comment 6 Ian 'Hixie' Hickson 2014-08-28 18:44:55 UTC
It wouldn't work because "repeat while" in English means something different than "while" in programming languages.

Anyway, I can add more indentation to this algorithm I guess.
Comment 7 Ian 'Hixie' Hickson 2014-09-17 22:58:23 UTC
Ok, let me know what you think of the update on IRC.
Comment 8 contributor 2014-09-17 22:58:36 UTC
Checked in as WHATWG revision r8784.
Check-in comment: Add in some clearer indentiation in the table sorting algorithm to make it easier to understand
https://html5.org/tools/web-apps-tracker?from=8783&to=8784