# Why is configuration in YAML and not Ruby?

**URL:** <https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604>\
**Category:** Rails\
**Created:** [February 19, 2006, 11:02pm UTC](https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604 "2006-02-19T23:02:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![neilw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e36b37/32.png) [@neilw](https://www.ruby-forum.com/u/neilw)\
**Post date:** [February 19, 2006, 11:02pm UTC](https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604/1 "2006-02-19T23:02:05Z")

</div>

On thing that has struck me about dynamic languages is that you don’t  
need configuration files at all. You can just alter the definitions  
directly in the Ruby code.

So if everything is Ruby and configuration files are frowned upon, why  
does Rails store the database connectors in a config file ‘database.yml’

What’s wrong with a ‘database.rb’ containing

development = { :adapter =\> ‘mysql’, :database =\> ‘depot\_development’,  
etc… }

plus whatever syntactic sugar is required to get the thing in the right  
place.

I know it doesn’t matter. I’m just trying to understand the logic or  
history behind it. At the moment it seems a bit of an anathema in an  
otherwise elegant structure.

Regards

NeilW

---

<div class="post-metadata">

**Author:** ![neilw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e36b37/32.png) [@neilw](https://www.ruby-forum.com/u/neilw)\
**Post date:** [February 20, 2006, 2:01am UTC](https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604/2 "2006-02-20T02:01:46Z")

</div>

On 2/19/06, Neil W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> etc… }
> 
> plus whatever syntactic sugar is required to get the thing in the right  
> place.
> 
> I know it doesn’t matter. I’m just trying to understand the logic or  
> history behind it. At the moment it seems a bit of an anathema in an  
> otherwise elegant structure.

The YAML file is just the Ruby hash you put in you rmessage, dumped  
out to a config file. YAML is nice because it’s easy to dump and  
reload.  
One problem with ‘database.rb’ is that it would be a little harder to  
make a change and save it.  
Stated another way, .rb files are meant to be edited by people, .yml  
files can easily be edited by people or by code.  
When the YAML file is read in, it becomes a regular old Hash.

---

<div class="post-metadata">

**Author:** ![neilw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e36b37/32.png) [@neilw](https://www.ruby-forum.com/u/neilw)\
**Post date:** [February 21, 2006, 12:22am UTC](https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604/3 "2006-02-21T00:22:07Z")

</div>

On 20/02/06, Wilson B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The YAML file is just the Ruby hash you put in your message, dumped  
> out to a config file. YAML is nice because it’s easy to dump and  
> reload.

Yes, but it’s also awful. _Lots_ of people have trouble with the  
‘two leading spaces, not tabs’ issue, for example. And how often do  
you reload (or  
dynamically write) your rails config hash?

A Ruby hash isn’t much harder to write out than a YAML hash  
(we’re not talking Java and XML here), and you’d have a lot more  
flexibility in doing things that (e.g.) yaml aliases are currently used  
for if  
you just had a class method to populate the config hash.

I’d suggest it’s YAML based for historical reasons -  
otherwise we’d be looking at routes.yml etc.

–  
Rasputin :: Jack of All Trades - Master of Nuns  
[http://number9.hellooperator.net/](http://number9.hellooperator.net/)

---

<div class="post-metadata">

**Author:** ![neilw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e36b37/32.png) [@neilw](https://www.ruby-forum.com/u/neilw)\
**Post date:** [February 21, 2006, 1:45am UTC](https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604/4 "2006-02-21T01:45:00Z")

</div>

On Mon, Feb 20, 2006, Dick D. wrote:

> I’d suggest it’s YAML based for historical reasons -  
> otherwise we’d be looking at routes.yml etc.

Except that routes can contain a bunch of logic, which you can’t put  
into YAML.

Configuration files are very rarely written in the same language as the  
app. Part of the idea is that you don’t want people to have to know the  
language to configure your application. I’m sure there are other  
reasons, that’s just the first one that comes to mind.

Ben

---

<div class="post-metadata">

**Author:** ![neilw](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/e36b37/32.png) [@neilw](https://www.ruby-forum.com/u/neilw)\
**Post date:** [February 21, 2006, 5:16am UTC](https://www.ruby-forum.com/t/why-is-configuration-in-yaml-and-not-ruby/70604/5 "2006-02-21T05:16:46Z")

</div>

> Configuration files are very rarely written in the same language as the  
> app. Part of the idea is that you don’t want people to have to know the  
> language to configure your application. I’m sure there are other  
> reasons, that’s just the first one that comes to mind.

## Actually, I really like Ruby for configuration. It’s actually just a legacy decision that database.yml is in YAML. We’ve been discussing various ways to refactor that into a nice Ruby configuration that would probably be part of environment.rb and friends. But it just hasn’t been high priority enough to work on yet.

David Heinemeier H.  
[http://www.loudthinking.com](http://www.loudthinking.com) – Broadcasting Brain  
[http://www.basecamphq.com](http://www.basecamphq.com) – Online project management  
[http://www.backpackit.com](http://www.backpackit.com) – Personal information manager  
[http://www.rubyonrails.com](http://www.rubyonrails.com) – Web-application framework
