我在YAML-wikipedia上读了它们,但并没有真正理解它们之间的主要区别。我看到有人使用。yaml扩展名,然而,Symfony2使用。yml扩展名。
YAML是一种人类可读的数据序列化格式,它采用了C、Perl和Python等编程语言的概念,以及XML和电子邮件数据格式的思想。
YAML是“YAML Ain't Markup Language”的递归首字母缩写。在YAML开发的早期,它的意思是“另一种标记语言”,[3],但后来它被重新解释(反向命名最初的缩写词),以区分其面向数据的目的,而不是文档标记。
那么,.yaml和.yml到底有什么不同呢?什么时候我们应该选择其中一种?
正如@David Heffeman所指出的,建议在可能的情况下使用.yaml,自2006年9月以来一直是这样的建议。
一些项目使用。yml主要是因为实现者/文档者的无知:他们想要使用YAML是因为可读性,或者其他格式中没有的其他特性,他们不熟悉推荐,可能在查看其他项目/库之后(没有质疑所做的是否正确),只是实现了工作。
最好的方法是在创建新文件时要严格(即使用.yaml),在接受输入时要宽容(即遇到。yml时允许输入),尽可能自动升级/纠正这些错误。
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).
另一方面:
Symfony2的Yaml (sic!)组件实现了Yaml 1.2版本规范中定义的选定功能子集。
因此,他们也使用推荐扩展的子集似乎是合适的。