15

Current configuration file is as follows:

mainwindow.title = 'test'
mainwindow.position.x = 100
mainwindow.position.y = 200

mainwindow.button.label = 'apply'
mainwindow.button.size.x = 100
mainwindow.button.size.y = 30

logger.datarate = 100
logger.enable = True
logger.filename = './test.log'

This is read with python to a nested dictionary:

{
  'mainwindow':{
    'button':{
      'label': {'value':'apply'},
       ...
  },
  'logger':{
     datarate: {'value': 100},
     enable: {'value': True},
     filename: {'value': './test.log'}
  }, 
  ...    
}

Is there a better way of doing this? The idea is to get XML type of behavior and avoid XML as long as possible. The end user is assumed almost totally computer illiterate and basically uses notepad and copy-paste. Thus the python standard "header + variables" type is considered too difficult.

The dummy user edits the config file, able programmers handle the dictionaries. Nested dictionary is chosen for easy splitting (logger does not need or even cannot have/edit mainwindow parameters).

8
  • 11
    The absolute simplest would be to build your client a small app that does nothing but edit these config files. Mar 26, 2012 at 16:42
  • 11
    The simplest configuration file for humans is: Do what I want. It's the hardest for computers, though :P
    – Sjoerd
    Mar 26, 2012 at 17:15
  • @PatrickHughes I would guess there already exists one. Are you aware of such a program. I would not like to take time just to "pretty print" simple things. The problem is that adding small program breaks requires more. I mean every computer has vim, textedit or notepad.
    – Juha
    Mar 27, 2012 at 9:16
  • @sjoerd This is what I wanted to know. Is there algorithms that are more on the human language than programs in this sense.
    – Juha
    Mar 27, 2012 at 9:16
  • 2
    Users can break anything. If they're going to edit it manually, be prepared to support mainwindow.title =='test"
    – MSalters
    Mar 27, 2012 at 14:37

6 Answers 6

16

You could use something like YAML. Here is a link to an example:

http://www.yaml.org/start.html

--- !clarkevans.com/^invoice
invoice: 34843
date   : 2001-01-23
bill-to: &id001
    given  : Chris
    family : Dumars
    address:
        lines: |
            458 Walkman Dr.
            Suite #292
        city    : Royal Oak
        state   : MI
        postal  : 48046
ship-to: *id001
product:
    - sku         : BL394D
      quantity    : 4
      description : Basketball
      price       : 450.00
    - sku         : BL4438H
      quantity    : 1
      description : Super Hoop
      price       : 2392.00
tax  : 251.42
total: 4443.52
comments: >
    Late afternoon is best.
    Backup contact is Nancy
    Billsmer @ 338-4338.

You can find Python bindings for it at PyYAML. It's a little more user friendly than JSON (which is what your second example looks like).

4
  • 12
    YAML is dandy, but definitely not the simplest.
    – 9000
    Mar 26, 2012 at 15:09
  • 1
    I thought simplest in the context of his question: "get XML type of behavior and avoid XML as long as possible". I'm not sure of anything simpler, while meeting this requirement.
    – jmq
    Mar 26, 2012 at 15:58
  • hmm, so is my first codeblock YAML if I change the "." and "=" to ":" and lose the aphostropes ? There is a bit redundant data but then it would be up to the user which notation he likes best.
    – Juha
    Mar 27, 2012 at 12:47
  • 3
    I'm fairly certain non-technical users are going to get the indentation wrong - let alone the more obscure stuff like the > after comments:, and the & and * in front of id001
    – Izkata
    Mar 27, 2012 at 18:16
6

The best thing you can do is provide a mockup of your solution, and perhaps a mockup of a couple other solutions, and ask two or three representative users of your system. They will be much better at telling you what they like than the self-selected people who answer questions on this site.

That being said, for "basically computer illiterate" users I think the format you show in your question is probably the best plain text format. If they really are computer illiterate, you might want to consider a simple GUI so they don't have to hand-edit configuration files.

3

Lose everything you can lose. name.name.name=value, each on a separate line, is about as simple as you can get. You don't need the quotes for parsing, you know when true is a boolean and when true is a string, don't make the "dumb human" tell you that. For strings, if the field shouldn't have leading/trailing blanks, strip them yourself.

3

Imagine a Chinese person who doesn't know English who's trying to read your configuration file. Alternatively, imagine the configuration file is in Arabic (and that you don't known Arabic). Now ask yourself, is this really human readable?

Even if the reader does know English, they've still got no idea if "logger.datarate = 100" means 100 characters per second, or 100 GiB per hour, or 100 chickens per metric ton.

The most human readable file format, is a binary file with a decent GUI based dialog box/wizard/configurator (with internationalisation, help system, etc).

2

I'm with Patrick Hughes. Build a simple app for editing configurations. The config file itself could be a little more complex and might contain attributes for the editor to use (display name, help text, value type, min/max value, etc).

2
  • 1
    the problem here is that the app has to support osx, win and ubuntu and have access to filesystem. So my only alternative is static python executable (and wx for native look). Or is there another languages? Can you make static java executables?
    – Juha
    Mar 27, 2012 at 19:06
  • A QT app would be a simple and conformal solution in your case
    – Riga
    Nov 18, 2014 at 8:59
2

I say what you have (properties file) is already the best human readable configuration format. :)

Here are my arguments:

  • Properties file is just key/value pair. Easily readable by human.
  • Terse syntax, not like xml.
  • Easily nest-able, with '.', like in your example.
  • Flat structure allows easy diffing in a source controlled environment.

That last point is actually pretty important. Given that projects nowadays are all divided up into branches, configuration file can cause tons of pain when you are merging branches. Flat file format like properties file are easier to merge than tree structure file.

Not the answer you're looking for? Browse other questions tagged or ask your own question.