不同配置格式的优缺点? [英] Pros and cons for different configuration formats?

查看:131
本文介绍了不同配置格式的优缺点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过人们使用* .cfg(Python Buildout),*.xml(Gnome),*.json(Chrome扩展程序),*.yaml(Google App Engine),*.ini甚至是* .py应用程序配置文件(例如Django).

I've seen people using *.cfg (Python Buildout), *.xml (Gnome), *.json (Chrome extension), *.yaml (Google App Engine), *.ini and even *.py for app configuration files (like Django).

我的问题是:为什么会有这么多不同的配置文件格式?我可以从xml vs json方法(更不用说冗长)或Python的方法(有时您有一个Python应用程序,不想只使用特定的模块来解析配置文件)中看到一种优势,但是其他方法又如何呢?方法?

My question is: why there are so many different configuration file formats? I can see an advantage from a xml vs json approach (much less verbose) or a Python one (sometimes you have a Python app and don't want to use a specific module just to parse a config file), but what about the other approaches?

我知道格式比我举例说明的那些配置文件还要多.彼此相比,它们的真正优势是什么?历史原因?与不同系统兼容吗?

I know there are even more formats than those configuration files I exemplified. What are really their advantages in comparison to each other? Historical reasons? Compatibility with different systems?

如果您要启动一个应用程序以读取某种配置文件(带有插件生态系统),您将使用哪个文件?

If you would start an application to read some kind of configuration files (with a plugin ecosystem), which one would you use?

我列举的哪个是最古老的?你知道它的历史吗?

Which ones that I gave as example are the oldest ones? Do you know it's history?

推荐答案

主要是个人喜好,目的和可用的库.我个人认为xml对于配置文件来说太冗长了,但是它很流行并且具有很棒的库.

It's mostly personal preference, purpose, and available libraries. Personally I think xml is way too verbose for config files, but it is popular and has great libraries.

.cfg,.ini是运行良好的旧格式,许多语言都有一个包含的库可以读取它们.我已经在Java,Python,C ++中使用了它,没有任何问题.它实际上不能用作数据交换格式,如果我要传递数据,则可能会使用相同的格式进行配置和数据交换.

.cfg, .ini are legacy formats that work well and many languages have an included library that reads them. I've used it in Java, Python, C++ without issues. It doesn't really work as a data interchange format and if I am passing data I will probably use the same format for config and data interchange.

yaml和json位于xml和cfg/ini之间.您可以在两者中定义许多数据结构,也可以像cfg一样是简单的键值.这两种格式在python中都具有出色的库,并且我假设许多其他语言也都具有库.我相信json是yaml的子集.

yaml, and json are between xml and cfg/ini. You can define many data structures in both, or it can be a simple key-value like with cfg. Both of these formats have great libraries in python and I'm assuming many other languages have libraries as well. I believe json is subset of yaml.

我从未使用过python文件作为配置,但是它对于django似乎确实很好用.它确实允许您在配置中包含一些可能有用的代码.

I've never used a python file as config, but it does seem to work well for django. It does allow you to have some code in the config which might be useful.

上次我选择的格式是yaml.它很简单,但是具有一些不错的功能,并且python库易于安装并且非常好.杰森紧随其后,由于yaml库解析了json,所以我选择了yaml.

Last time I was choosing a format I chose yaml. It's simple but has some nice features, and the python library was easy to install and really good. Json was a close second and since the yaml library parsed json I chose yaml over it.

这篇关于不同配置格式的优缺点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆