Sorting, naturally

All posts, RSS Feed

In RPGpad we have a lot of lists and overviews that can help you gain some insight into the pages, people, locations, and other things in your campaign. In this post we explain some of the background on why we changed how some of those lists are sorted.

Sometimes when you see a list of something on a computer it appears to be sorted. Such a list could look something like this:

Sorted Fruits
    No fruits to sort. You can add some with the field below.

    In the demo above, you can add your own fruits by typing their names in the input field, and hitting the ‘New fruit’ button. Go ahead! (If you can’t think of a lot of fruits, the computer isn’t picky—anything you type will work, or you can just click on these fruits: “Grape”, “Melon”, “coconut”)

    Unfortunately, computers don’t really sort things in the same way humans do unless you tell them in excruciating detail how to sort them. As you explore the sorting of fruits above, you might notice that something strange is happening: “Orange” goes above “coconut”, even though ‘c’ should go before ‘o’.

    By default, computers sort all upper case letters (also called capital letters) before lower case letters, so anything starting with A-Z will go before anything starting with “a”. Likewise, anything starting with a digit will go before any letters, and there’s also a whole thing with the sorting order of punctuation and other symbols that seem to arbitrarily go before, or after of all the letters. We call this the “ASCIIbetical” sorting order, which is a contraction of ASCII and alphabetical, as the binary encoding of characters is used to sort the words.

    Feel free to explore that some more by adding strange and non-existant fruits! Interesting things to try are the “!exclaberry” or the “@nanas”, or the not-very-fruity things known as “Session 1”, “Session 2”, and “Session 10”:

    Sorted Fruits anything
      No things to sort. You can add some with the field below.

      As you can see, what the computers does here by default is a decent effort but not very good. Especially the example “Session 1”, “Session 10” and “Session 2” items are just sorted wrong.

      To fix the issues of the default sorting, we have implemented something called natural sort order. This is an ordering that tries it’s best to sort things the way you would naturally do when sorting by hand.

      The result is a big improvement in how lists are sorted. The new ordering ignores the case of the things that are sorted, putting all things starting with the same letter together—regardless of whether someone wrote “Session” or “session”. And moreover, it puts things with numbers in them in the order you would expect:

      Natural sort order
        No things to sort. You can add some with the field below.

        Feel free to try it yourself: you can add any custom thing to sort in here and see where it would end up using natural sorting instead!

        The ordering you get here might be slightly different from the one you actually get in your campaign pages. The reason for this is that the actual ordering we use in RPGpad was written specifically for RPGpad. The custom implementation we use in campaigns is even more advanced and allows us to adjust and improve the ordering even further when we find things that can be sorted better—for example by taking into account that some game system might want special ordering for special rules pages.


        As always, we have this week’s changelog available with details. If you find something that you think is sorted the wrong way, feel free to open a thread in the technical forum or to report a bug. If you do, it would help immensely of you paste the list that you see, and tell us how you would expected it to be.