Config files

L

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
 
K

Konrad Meyer

--nextPart1254199.UTF7LLNFCE
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

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?
=20
Thanks

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

Regards,
=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart1254199.UTF7LLNFCE
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBHAY6+CHB0oCiR2cwRAu7/AJ9tjhLdCvcVCClPeDpV1xCl/y/wHwCcCeRc
x9leBbIM94xuettU3oYmNxM=
=sYCB
-----END PGP SIGNATURE-----

--nextPart1254199.UTF7LLNFCE--
 
B

BJ Dierkes

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')
 
D

dima

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

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

Phil Meier

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 said:
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')
 
P

Paul van Delst

Lee said:
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. :eek:) 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.
 
J

James Edward Gray II

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?

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top