Picture of stu

Config file design

  • Posted By Stuart Halloway on July 09, 2007
XML lends itself to big, ugly configuration files. Nevertheless, there is room for better and worse in configuration file design. Which of these do you like better, and why?
<beans>
  <bean id="java-bean" class="di.FixedSource"/>
  <lang:jruby id="ruby-bean"
    script-source="file:ruby/message_source.rb"
    script-interfaces="di.MessageSource" />
</beans>
Or option 2:
<beans>
  <bean id="java-bean" class="di.FixedSource"/>
  <bean id="ruby-bean"
    lang:source="file:ruby/message_source.rb"
    lang:interfaces="di.MessageSource" />
</beans>
Comments
  1. Bob LeeJuly 09, 2007 @ 01:46 AM

    I don’t like either. Are you still using Spring?

  2. Sammy LarbiJuly 09, 2007 @ 04:27 AM

    The first one, because it doesn’t repeat the “lang”, but the 2nd one, because the “bean” describes itself as such, but then again the “bean” isn’t quite needed since it is contained within “beans.”

    I don’t really like either of them (as you can tell), but I if I chose one, it’d be the 2nd one because it seems easier to find what I’m looking for (i.e., I only need to write code to look for bean tags, not bean and lang:ruby tags)

    How about you?

  3. Justin ForderJuly 09, 2007 @ 06:37 AM

    Good point. Option 2 is clearly better – a Ruby bean is still a bean.

  4. StoffeJuly 09, 2007 @ 11:05 AM

    Liked the second one because I for some reason could immediately see what it did, it was much more human-readable. Probably because <bean>

  5. Tom HawtinJuly 09, 2007 @ 11:21 AM

    XML elements need to stand on their own. So the second option is least worse. What is a jruby?

    XML is such a mess.

  6. UzytkownikJuly 09, 2007 @ 12:30 PM

    Second one – use namespaces.

  7. JoeJuly 09, 2007 @ 07:44 PM

    I don’t like either, but I prefer Option 2 for readability reasons similar to Stoffe’s. I also dislike XML namespaces. Would it be terrible to remove the “lang:” prefix in the ruby-bean attributes?