Some tracks take the syllabus tree ordering into account and use that for sorting
Some tracks sort by date-created (the default when you use the configlet to add new exercises)
The first two can be detected pretty easily to flag tracks that are not sorted alphabetically and not sorted by difficulty to do a sorting-cleanup. Do you want a PR on your track to sort the exercises?
If you want to sort by difficulty then name, you can use this:
There’s a distinction to be made between sorting by numeric difficulty versus the difficulty on the website (easy, medium, or hard).
I’m a strong proponent of sorting by displayed, not numeric, difficulty. Arturo, CoffeeScript, LFE, Pyret, Racket, Rescript, and VimScript are sorted that way. I solo maintain Arturo and Pyret so I’ll add a CI check there to ensure exercises are sorted correctly.
For a while, I maintained CFML, D, Emacs Lisp, and Red. During that time, I largely sorted their exercises by displayed difficulty as well, but it’s up to the current maintainers what they want to do. CFML is notably unmaintained now so if we don’t have a recommended default sort order, maybe pick one for that track.
Hrm. A better starting point here might be a GHA (http://github.com/exercism/github-actions/) that checks if exercises are sorted with a sort-selector (eg one-or-more of “difficulty”, “displayed-difficulty”, “slug”). I might work on that first then tracks could opt into that GHA.
It’s probably worth then documenting the commonly used sorting methods in the Exercism docs so maintainers have a reference when choosing a sort strategy.
Yeah, good catch. I was assuming Isaac meant sorting alphabetically by exercise name, not slug. Slugs are likely more meaningful to maintainers than students.
I meant slug, which is used a fair bit for sorting
I reworked the check to dump the slugs and use diff to compare sorted to unsorted … and made use of sort_by() with injected paths. This allows track maintainers to set any arbitrary sort keys, eg .difficulty, .name or .bucket, .slug. This makes the sorting more flexible (allowing arbitrary sorting) and more brittle (code injection, allows invalid path expressions).
The proposed GHA is for checking if the exercises are sorted a particular way. Should there be an optional mode to then force that sort or is that out of scope? The original post mentioned sorting the exercises which is a separate action from checking if they are already sorted.
I’m fine with or without that option, but I figured I’d bring it up for clarity.
Sorting the exercises is not part of the plan here. IIRC jq and configlet format the JSON differently which makes auto sort-and-format a bit more involved.
If you know nim, this sorting could be defined directly (and optionally) in the config.json and configlet create would ideally insert new exercises in the correct place. configlet fmt and/or configlet lint could check it.
Yes, otherwise “ETL” sorts before “Eliud’s Eggs”, “ISBN Verifier” sorts before “Intergalactic Transmission” and “RNA Transcription” sorts before “Reverse String”