Config files

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

Quoth Lee Jarvis:

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

Thanks

Personally, I think XML is a load of crap. If your configuration is simple
enough (and it likely is) I'd use YAML. If you need anything more
complicated, you can always use your own scheme, Marshal, or a sqlite db or
something.

Regards,

···

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertillnoon.com/

I prefer using standard *nix style configuration files in the form of 'param = value'. I wrote a class to read this type of configuration file called ParseConfig.

http://rubyforge.org/projects/parseconfig/

It is available via rubygems/rubyforge:

gem install parseconfig

Usage is really simple. Say you have a config file that looks like:

···

---
user = 'username'
pass = 'password'
log_file = '/var/log/mylog'
---

A quick example to use this config would be:
  ---
require('rubygems')
require('parseconfig')

config = ParseConfig.new('/path/to/config/file')
user = config.get_value('user')
pass = config.get_value('pass')
log_file = config.get_value('log_file')
---

If you all have any suggestions, etc... you can submit them via the RubyForge Tracker.

On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

Thanks
--
Posted via http://www.ruby-forum.com/\.

Lee Jarvis wrote:

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

I tried to roll my own once - and now I use yaml. :o) Nice and simple, easy to use for both simple and complicated[*] configuration files, and you can go on with more interesting stuff.

Besides, whichever you choose, you can always change it if your application outgrows it, right?

cheers,

paulv

[*] Well, actually, in this case it wasn't a configuration file per se, but a specification for a derived type definition in Fortran95 along with associated netcdf attributes for I/O. Works a treat, though.

YAML tends to work out well, when it's very simple data fields being collected. That said, YAML's syntax rules are quite complex and asking a user to edit any non-trivial data in the format is a bad idea, in my opinion.

If you need markup at all, use XML. It's a markup language, after all. YAML is not.

Also, while more verbose, XML has a much easier syntax that far more people are familiar with. I'm not saying that means you have to use it, but it's something to stay aware of.

Finally, I've used this trick a couple of times now and I just love it:

#!/usr/bin/env ruby -wKU

require "ostruct"

module Config
   module_function

   def load_config_file(path)
     eval <<-END_CONFIG
     config = OpenStruct.new
     #{File.read(path)}
     config
     END_CONFIG
   end
end

__END__

That let's me do my configurations in pure Ruby, which may or may not be appropriate for your needs.

I guess the most important thing is to consider your audience.

James Edward Gray II

···

On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

As told so menu times before: There is no golden hammer.
The optimal solution depends on your application needs and estimation
about future use of it.
The yaml is more human readable. XML is universal and can be used by
other applications but has some overhead. Classical config files are
something programmers used to and it's portable and more or less human
readable. There is also a data base configuration but that is out of
the scope because you should have configuration for database that
holds configurations for application.

Personally, the yaml version is a way to start. If some need emerge
that can't be natively expressed by yaml than you should move to other
solution. But most probably you will stay on yaml.

···

On Oct 2, 5:26 am, BJ Dierkes <wdier...@5dollarwhitebox.org> wrote:

I prefer using standard *nix style configuration files in the form of
'param = value'. I wrote a class to read this type of configuration
file called ParseConfig.

http://rubyforge.org/projects/parseconfig/

It is available via rubygems/rubyforge:

gem install parseconfig

Usage is really simple. Say you have a config file that looks like:

---
user = 'username'
pass = 'password'
log_file = '/var/log/mylog'
---

A quick example to use this config would be:
  ---
require('rubygems')
require('parseconfig')

config = ParseConfig.new('/path/to/config/file')
user = config.get_value('user')
pass = config.get_value('pass')
log_file = config.get_value('log_file')
---

If you all have any suggestions, etc... you can submit them via the
RubyForge Tracker.

On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:

> I am writing an application that will read and grab values from a
> configuration file. I am wondering what peoples opinions are on
> what to
> use. YAML? XML? Does anyone have any preference? Are any better
> then the
> others or is it just down to user preference?

> Thanks
> --
> Posted viahttp://www.ruby-forum.com/.

I like using Ruby directly for doing stuff like this (if the "configuration file" is under my control).

Example:
module MyConfig
   user = 'username'
   pass = 'password'
   log_file = '/var/log/mylog'
end
=> Store in file 'MyConfig.rb'

test.rb:
require 'MyConfig'

p MyConfig::User
p MyConfig::Pass
p MyConfig::Log_file

BR Phil Meier

BJ Dierkes schrieb:

···

I prefer using standard *nix style configuration files in the form of 'param = value'. I wrote a class to read this type of configuration file called ParseConfig.

http://rubyforge.org/projects/parseconfig/

It is available via rubygems/rubyforge:

gem install parseconfig

Usage is really simple. Say you have a config file that looks like:

---
user = 'username'
pass = 'password'
log_file = '/var/log/mylog'
---

A quick example to use this config would be:
---
require('rubygems')
require('parseconfig')

config = ParseConfig.new('/path/to/config/file')
user = config.get_value('user')
pass = config.get_value('pass')
log_file = config.get_value('log_file')
---

If you all have any suggestions, etc... you can submit them via the RubyForge Tracker.

On Oct 1, 2007, at 6:21 PM, Lee Jarvis wrote:

I am writing an application that will read and grab values from a
configuration file. I am wondering what peoples opinions are on what to
use. YAML? XML? Does anyone have any preference? Are any better then the
others or is it just down to user preference?

Thanks
--
Posted via http://www.ruby-forum.com/\.

BJ Dierkes wrote:

I prefer using standard *nix style configuration files in the form of
'param = value'. I wrote a class to read this type of configuration
file called ParseConfig.

http://rubyforge.org/projects/parseconfig/

Ooo, thank you.. I've been meaning to look for some thing like that :slight_smile:

I have actually never needed to deal with config files from this perspective.
Personally from the point of view of Joe Blow. I prefer a syntax like most
unix style config files.

# Comment
parm = value

Along with the ini file, it makes for a very easy to edit file. It's just a
matter of figuring out what does what for the end user. (IMHO)

TerryP.

···

--
    
Email and shopping with the feelgood factor!
55% of income to good causes. http://www.ippimail.com

Config files should be plain Ruby (written of the top of my head). Why parse
for yourself when Ruby has a perfectly fine one?

config.ini

param1 = value1
param2 = value2
...

parser.rb

def method_missing(method_name, *args)
  if method_name.match(/=/)
     @config[method_name] = args[0]
  end
end

require "config.ini"

@config["param1"] # => value1

This of course, or YAML, because that's just so bloody easy.

Jason

···

On 10/3/07, Terry Poulin <bigboss64@ippimail.com> wrote:

BJ Dierkes wrote:
> I prefer using standard *nix style configuration files in the form of
> 'param = value'. I wrote a class to read this type of configuration
> file called ParseConfig.
>
> http://rubyforge.org/projects/parseconfig/
>
>

Ooo, thank you.. I've been meaning to look for some thing like that :slight_smile:

I have actually never needed to deal with config files from this
perspective.
Personally from the point of view of Joe Blow. I prefer a syntax like most
unix style config files.

# Comment
parm = value

Along with the ini file, it makes for a very easy to edit file. It's just
a
matter of figuring out what does what for the end user. (IMHO)

TerryP.

--

Email and shopping with the feelgood factor!
55% of income to good causes. http://www.ippimail.com