Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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

share|improve this question
9  
The absolute simplest would be to build your client a small app that does nothing but edit these config files. –  Patrick Hughes Mar 26 '12 at 16:42
7  
The simplest configuration file for humans is: Do what I want. It's the hardest for computers, though :P –  Sjoerd Mar 26 '12 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 '12 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 '12 at 9:16
1  
Users can break anything. If they're going to edit it manually, be prepared to support mainwindow.title =='test" –  MSalters Mar 27 '12 at 14:37
show 1 more comment

migrated from codereview.stackexchange.com Mar 26 '12 at 14:59

This question came from our site for peer programmer code reviews.

4 Answers

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

share|improve this answer
5  
YAML is dandy, but definitely not the simplest. –  9000 Mar 26 '12 at 15:09
    
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 '12 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 '12 at 12:47
1  
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 '12 at 18:16
add comment

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.

share|improve this answer
add comment

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

share|improve this answer
    
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 '12 at 19:06
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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