Configuration Item Order


Currently, package configuration is ordered alphabetically by the configuration key name. With the introduction of the use of json-schema for configuration, could there be a better way to allow us to order configuration values?

Alphabetical ordering can cause very important configuration (that I would like to come first) to get lost among other options. A simple solution would be to not alphabetically order the config keys, and use them in the order specified in module.exports:

module.exports =
    first: ''
    aSecond: ''

A more advanced solution would allow specifying an order:

module.exports =
      title: 'Second'
      description: 'You should see this second in the list of package config'
      type: 'boolean'
      default: true
      order: 2
      title: 'First'
      description: 'You should see this first in the list of package config'
      type: 'boolean'
      default: true
      order: 1

Either is preferable to the current technique. Thoughts?


It would have to use some form of order parameter like you’ve outlined, since the order of keys in a dictionary is not guaranteed to be preserved (in JavaScript). I’d make the order optional, and sort the rest alphabetically.


I almost posted the same thing. But then I remembered that V8 does maintain a strict ordering and we only need to support V8.


I did not know that. Thanks for the info!


This is one of those things that is likely to change out from under us at some point in time though unless Google makes a guarantee of it?


You are probably right.

But so far they have been adamant about sticking to it. A few years ago there was a flurry of issues about their ordering not matching other browsers (they sort anything that looks like a number to the top). I don’t have the link but they refused to discuss it.


I don’t think putting in an optional schema parameter along the lines of displayOrder or some such will hurt though. That way those developers who prefer a specific display order can have it, and it also guards us against possible future regressions in V8 (unlikely or not).


That’s the kind of thing where the fact that sort order is undefined is a defense. I imagine that conversation going something like this:

End User: Your dictionary key sort order doesn’t match other browsers!
Google: We’re compliant with the standard!
End User: Well, yes … but you see the fact that the sort order doesn’t match is problematic for us …
Google: We’re standards compliant! La-la-la-la-la!

Ah, the wonders of undefined behavior … :laughing:

Actually, my favorite example of “undefined” behavior is from the BeOS Kernel Kit API:

int32 is_computer_on(void)

Returns 1 if the computer is on. If the computer isn’t on, the value returned by the function is undefined.


Haha that is gold. (found reference here).

Also, underneath that method is:

double is_computer_on_fire(void).
Returns the temperature of the motherboard if the computer is currently on fire. If the computer isn’t on fire, the function returns some other value.

Because the value returned should be “what are you still doing debugging the Kernel API?”


Looks like this would be very easy to accomplish:

for name in _.keys(settings).sort() <<<<<<<<<< HERE
  , namespace, name, settings[name])


PR #273 fixes this:

  • [x] Allows package authors to specify an order field in their package config schema
  • [x] Sorts settings in settings-view by the order (if specified)
  • [x] Falls back to existing default behavior when no order is specified, or when two items with the same order exist

Configuration example:

module.exports =
      title: 'I Should Come Second'
      description: 'Really, I come second'
      type: 'boolean'
      default: true
      order: 2
      title: 'First'
      description: 'Winner winner'
      type: 'string'
      default: ''
      order: 1
      title: 'I am in 3rd place'
      description: 'Hi'
      type: 'string'
      default: ''
      title: 'I am in last because I am alphabetically inferior'
      description: 'Bye'
      type: 'string'
      default: ''