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 -- Posted via http://www.ruby-forum.com/.
On 2/19/06, Neil Wilson <aldursys@gmail.com> wrote:> 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. >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.
On 20/02/06, Wilson Bilkovich <wilsonb@gmail.com> 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/
On Mon, Feb 20, 2006, Dick Davies 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
David Heinemeier Hansson
2006-Feb-21 04:15 UTC
[Rails] Why is configuration in YAML and not Ruby?
> 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 Hansson http://www.loudthinking.com -- Broadcasting Brain http://www.basecamphq.com -- Online project management http://www.backpackit.com -- Personal information manager http://www.rubyonrails.com -- Web-application framework