296

I read them on YAML-wikipedia but not really understood the main difference between them. I saw there are someone using .yaml extension, however, Symfony2 use .yml extension.

YAML is a human-readable data serialization format that takes concepts from programming languages such as C, Perl, and Python, and ideas from XML and the data format of electronic mail.

YAML is a recursive acronym for "YAML Ain't Markup Language". Early in its development, YAML was said to mean "Yet Another Markup Language",[3] but it was then reinterpreted (backronyming the original acronym) to distinguish its purpose as data-oriented, rather than document markup.

So, how exactly the different between .yaml and .yml? When should we prefer one over the other?

Anthon
  • 69,918
  • 32
  • 186
  • 246
lvarayut
  • 13,963
  • 17
  • 63
  • 87

2 Answers2

482

File extensions do not have any bearing or impact on the content of the file. You can hold YAML content in files with any extension: .yml, .yaml or indeed anything else.

The (rather sparse) YAML FAQ recommends that you use .yaml in preference to .yml, but for historic reasons many Windows programmers are still scared of using extensions with more than three characters and so opt to use .yml instead.

So, what really matters is what is inside the file, rather than what its extension is.

roottraveller
  • 7,942
  • 7
  • 60
  • 65
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • 18
    Attributing preference for ".YML" over ".YAML" to the DOS 8.3 character convention is IMO a red herring. More likely, this resulted from the fact that three (3) characters starting with "Y" is sufficiently clear, since few extensions start with "Y." – MarkDBlackwell Aug 03 '16 at 22:59
  • 70
    The trend toward 3-character extensions was clearly reinforced by Windows and its 8.3 rule. The idea that people today are acting out of fear might be an exaggeration, but that they are acting out of habit seems hard to dispute, and that this practice was heavily influenced by Windows also seems hard to dispute. – iconoclast Apr 06 '17 at 20:12
  • 6
    it might be of interest that 3-character extensions predate Microsoft. E.g., DEC's PDP-11 had 6.3 filenames encoded in 3 16-bit words: https://en.wikipedia.org/wiki/DEC_Radix-50#16-bit_systems – Walter Tross Jun 05 '19 at 06:28
  • 1
    For me the concern was if there is a version difference (like with MS office, with the x at the end of new versions). Thanks for the clarification. – gagarwa Oct 28 '20 at 20:28
  • I did prefer 3-character extensions because I was a little 'scared' of having some random problem created in the future by some other system or program stuck with the 8.3 limitation. However, in reading this, I became cognizant of this antiquated 'fear', and maybe it is a little silly. Maybe it's time to be BRAVE! .yaml and .json all the way! – calarin Nov 07 '21 at 19:59
  • Microsoft Azure DevOps (marketed as a platform independent product) seems to want you to use the .yml extension. For example, when you create a new pipeline in Azure DevOps, the filename by default is called azure-pipelines.yml. You have to go in and manually change the extension to .yaml if you want to use the 4 character extension. – dcp Jun 19 '23 at 13:44
  • @dcp well, this is common with windows, many developers on Windows are still scared of extensions that don't have 3 characters – David Heffernan Jun 19 '23 at 16:57
36

As @David Heffeman indicates the recommendation is to use .yaml when possible, and the recommendation has been that way since September 2006.

That some projects use .yml is mostly because of ignorance of the implementers/documenters: they wanted to use YAML because of readability, or some other feature not available in other formats, were not familiar with the recommendation and and just implemented what worked, maybe after looking at some other project/library (without questioning whether what was done is correct).

The best way to approach this is to be rigorous when creating new files (i.e. use .yaml) and be permissive when accepting input (i.e. allow .yml when you encounter it), possible automatically upgrading/correcting these errors when possible.

The other recommendation I have is to document the argument(s) why you have to use .yml, when you think you have to. That way you don't look like an ignoramus, and give others the opportunity to understand your reasoning. Of course "everybody else is doing it" and "On Google .yml has more pages than .yaml" are not arguments, they are just statistics about the popularity of project(s) that have it wrong or right (with regards to the extension of YAML files). You can try to prove that some projects are popular, just because they use a .yml extension instead of the correct .yaml, but I think you will be hard pressed to do so.

Some projects realize (too late) that they use the incorrect extension (e.g. originally docker-compose used .yml, but in later versions started to use .yaml, although they still support .yml). Others still seem ignorant about the correct extension, like AppVeyor early 2019, but allow you to specify the configuration file for a project, including extension. This allows you to get the configuration file out of your face as well as giving it the proper extension: I use .appveyor.yaml instead of appveyor.yml for building the windows wheels of my YAML parser for Python).


Additionally there is the consideration that there is a YML format, a variant of XML that has been around for about as long as YAML. People using that format, or even those being familiar with that, propably expect a .yml file to indicate a file containing a YML document instead of a YAML document.


On the other hand:

The Yaml (sic!) component of Symfony2 implements a selected subset of features defined in the YAML 1.2 version specification.

So it seems fitting that they also use a subset of the recommended extension.

Anthon
  • 69,918
  • 32
  • 186
  • 246