Configuration Item Order


#1

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 =
  config:
    first: ''
    aSecond: ''

A more advanced solution would allow specifying an order:

module.exports =
  config:
    aSecond:
      title: 'Second'
      description: 'You should see this second in the list of package config'
      type: 'boolean'
      default: true
      order: 2
    first:
      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?


#2

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.


#3

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


#4

I did not know that. Thanks for the info!


#5

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?


#6

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.


#7

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).


#8

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.


#9

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?”


#10

Looks like this would be very easy to accomplish: https://github.com/atom/settings-view/blob/6f158f4256397bb2b51a4d60e0a51f9fc383a8b3/lib/settings-panel.coffee#L53

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

#11

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 =
  config:
    aSecondOption:
      title: 'I Should Come Second'
      description: 'Really, I come second'
      type: 'boolean'
      default: true
      order: 2
    zFirstOption:
      title: 'First'
      description: 'Winner winner'
      type: 'string'
      default: ''
      order: 1
    cThird:
      title: 'I am in 3rd place'
      description: 'Hi'
      type: 'string'
      default: ''
    dFourth:
      title: 'I am in last because I am alphabetically inferior'
      description: 'Bye'
      type: 'string'
      default: ''