tags:

views:

386

answers:

5

Why would one choose YAML over XML or any other formats?

+4  A: 

I would chose YAML if the documents needed to be edited or created by humans. Just a thought.

Sergio Acosta
+6  A: 

YAML's main advantages are human readability and compactness. Oh, and it's widely supported across various platforms and languages.

YAML is very popular in the Ruby community, where it's mainly used in preference to XML for configuration files in Rails and Merb for example.

warren_s
+8  A: 

I agree with Sergio; YAML provides a format which is easily editable by humans, but also a good way to cleanly represent data structures.

YAML tends to be much more human-readable, IMO.

YAML is more of a data serialisation technique, rather than a markup language.

David Precious
As it says "YAML aint markup language!" ;-)
warren_s
+1  A: 

What type of application/utilization is YAML best suited for?

This is hard to clearly answer. Instead, I'll try provide some examples of what YAML isn't good for (in my humble opinion).

<name type="string">Orion</name>
<age type="integer">26</age>

This is a case of where it is useful to mix both attributes and values in XML. YAML doesn't have attributes, so you have to use type inference to decide what's a date/integer/string/etc - this fails for complex or user-defined types.

<user>
  .... 10 lines of stuff
  <sub-user>
    ...15 more lines of stuff
  </sub-user>
  .... 10 more lines of stuff belonging to user
</user>

This is a case where the closing tags in XML provide a lot of benefit. If you were to format the above data in YAML, using only indentation to provide 'scope', it would be a lot harder to tell where things start and end.

For good measure, here's a quote from the official yaml spec at yaml.org

YAML is primarily a data serialization language. XML was designed to be backwards compatible with the Standard Generalized Markup Language (SGML) and thus had many design constraints placed on it that YAML does not share. Inheriting SGML’s legacy, XML is designed to support structured documentation, where YAML is more closely targeted at data structures and messaging. Where XML is a pioneer in many domains, YAML is the result of lessons learned from XML and other technologies.

Orion Edwards
A: 

I use YAML as a cheap and easy replacement to writing a domain-specific language (particularly in cases where other developers will be doing maintenance; I'm not sure I'd use it when non-developers would be maintaining it)

Tony Arkles