373

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?

0

2 Answers 2

610

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.

9
  • 24
    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." Commented Aug 3, 2016 at 22:59
  • 84
    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
    Commented Apr 6, 2017 at 20:12
  • 8
    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: en.wikipedia.org/wiki/DEC_Radix-50#16-bit_systems Commented Jun 5, 2019 at 6: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
    Commented Oct 28, 2020 at 20:28
  • 3
    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
    Commented Jun 19, 2023 at 13:44
56

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.

1
  • 2
    Symfony now uses .yaml format and supports .yml too Commented Nov 19, 2020 at 14:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.