配置文件什么时候成为一种编程语言?
我已经考虑配置文件及其与代码的关系有一段时间了,根据风向和日期,我的观点似乎会发生变化。 但我越来越回想起我在学习 Lisp 时最初的认识:数据和代码之间几乎没有什么区别。 对于配置文件来说,这似乎更加正确。 从正确的角度来看,Perl 脚本只不过是 Perl 的配置文件。 这往往会对 QA 和劳动分工(例如谁应该负责更改配置文件)等任务产生相当严重的后果。
从配置文件到成熟语言的转变通常很慢,并且似乎是由拥有通用系统的愿望驱动的。 大多数项目似乎都是从小规模开始的,只有一些配置项,例如在哪里写入日志、在哪里查找数据、用户名和密码等。但随后它们开始增长:功能开始能够打开或关闭,操作的时间和顺序开始受到控制,并且不可避免地有人想要开始向其中添加逻辑(例如,如果机器是 X,则使用 10;如果机器是 Y,则使用 15)。 在某一点上,配置文件成为一种特定于域的语言,而且是一种写得很糟糕的语言。
现在我已经开始铺垫,以下是我的问题:
- 配置的真正目的是什么 文件?
- 是否应尝试保留 配置文件简单吗?
- 谁应该负责制作 对他们的改变(开发者、用户、 管理员等)?
- 他们是否应该受到源代码控制 (见问题3)?
正如我之前所说,我对这些问题的答案不断变化,但现在我在想:
- 允许非程序员改变 很快就会有大量的行为
- 是的,任何不粗俗的行为 粒度应该在
- 用户应该负责的 代码中 配置文件和程序员应该 负责配置 配置文件和代码之间的层 提供更细粒度的控制 应用程序的
- 否,但更细粒度的中间层应该是
I have been mulling over config files and their relationship to code for a while now and depending on the day and direction of the wind my opinions seem to change. More and more though I keep coming back to the realization I first had while learning Lisp: there is little difference between data and code. This seems doubly true for config files. When looked at in the right light a Perl script is little more than a config file for perl. This tends to have fairly heavy consequences for tasks such as QA and divisions of labor like who should be responsible for changing config files.
The creep from config file to full fledged language is generally slow and seems to be driven by the desire to have a generic system. Most projects seem to start out small with a few config items like where to write logs, where to look for data, user names and passwords, etc. But then they start to grow: features start to be able to be turned on or off, the timings and order of operations start to be controlled, and, inevitably, someone wants to start adding logic to it (e.g. use 10 if the machine is X and 15 if the machine is Y). At a certain point the config file becomes a domain specific language, and a poorly written one at that.
Now that I have rambled on to set the stage, here are my questions:
- What is the true purpose of a config
file? - Should an attempt be made to keep
config files simple? - Who should be responsible for making
changes to them (developers, users,
admins, etc.)? - Should they be source controlled
(see question 3)?
As I said earlier my answers to these questions shift constantly, but right now I am thinking:
- to allow a non-programmers to change
large chunks of behaviour quickly - yes, anything that is not coarsely
grained should be in code - users should be responsible for
config files and programmers should
be responsible for a configuration
layer between config files and code
that gives more fine grained control
of the application - no, but the finer grained middle layer should be
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(19)
非常有趣的问题!
我倾向于将我的配置文件限制为非常简单的“key=value”格式,因为我完全同意你的观点,配置文件可以很快成为成熟的程序。 例如,任何曾经尝试过“配置”OpenSER 的人都知道您所说的感觉:这不是配置,而是(痛苦的)编程。
当您需要您的应用程序以您今天无法想象的方式非常“可配置”时,那么您真正需要的是插件系统。 您需要以其他人可以编写新插件并将其连接到您的应用程序的方式来开发应用程序。
因此,回答您的问题:
配置文件的真正用途是什么?
我想说的是,允许安装您的应用程序的人能够调整一些与部署相关的参数,例如主机名、线程数、您需要的插件的名称以及这些插件的部署参数插件(查看 FreeRadius 的配置以获取此原理的示例)等。绝对不是表达业务逻辑的地方。
是否应该尝试使配置文件保持简单?
当然。 正如您所建议的,配置文件中的“编程”是可怕的。 我认为应该避免这种情况。
谁应该负责对它们进行更改(开发人员、用户、管理员等)?
一般来说,我会说部署应用程序的管理员。
它们是否应该受到源代码控制(参见问题 3)?
我通常不对配置文件本身进行源代码控制,但我对模板配置文件进行源代码控制,其中包含所有参数及其默认值以及描述其功能的注释。 例如,如果配置文件名为
database.conf
,我通常会对名为database.conf.template
的文件进行源代码管理。 当然,现在我正在谈论我作为开发人员所做的事情。 作为管理员,我可能希望对我为每次安装选择的实际设置进行源代码控制。 例如,我们远程管理数百台服务器,我们需要跟踪它们的配置:我们选择通过源代码控制来做到这一点。编辑:虽然我相信上述内容对于大多数应用程序都是正确的,但当然总有例外。 例如,您的应用程序可能允许其用户动态配置复杂的规则。 大多数电子邮件客户端允许用户定义电子邮件管理规则(例如,“所有来自‘john doe’并且“收件人:”字段中没有我的电子邮件都应被丢弃”)。 另一个示例是允许用户定义新的复杂商业报价的应用程序。 您还可以考虑像 Cognos 这样的应用程序,它允许用户构建复杂的数据库报告。 电子邮件客户端可能会为用户提供一个简单的界面来定义规则,这将生成一个复杂的配置文件(甚至可能是一些代码)。 另一方面,商业报价的用户定义配置可以以结构化方式保存在数据库中(既不是简单的键=值结构,也不是代码的一部分)。 一些其他应用程序甚至可能允许用户使用 python 或 VB 或其他一些支持自动化的语言进行编码。 换句话说......您的里程可能会有所不同。
Very interesting questions!
I tend to limit my config files to a very simple "key=value" format, because I fully agree with you that config files can very quickly become full-blown programs. For example, anyone who has ever tried to "configure" OpenSER knows the feeling you are talking about: it's not configuration, it's (painful) programming.
When you need your application to be very "configurable" in ways that you cannot imagine today, then what you really need is a plugins system. You need to develop your application in a way that someone else can code a new plugin and hook it into your application in the future.
So, to answer your questions:
What is the true purpose of a config file?
I would say, to allow the people who will install your application to be able to tweek some deployment-related parameters, such as host name, number of threads, names of the plugins you need, and the deployment-parameters for those plugins (check out FreeRadius's configuration for an example of this principle), etc.. Definitely not the place to express business logic.
Should an attempt be made to keep config files simple?
Definitely. As you suggested, "programming" in a config file is horrible. I believe it should be avoided.
Who should be responsible for making changes to them (developers, users, admins, etc.)?
In general, I would say admins, who deploy the application.
Should they be source controlled (see question 3)?
I usually don't source-control the configuration files themselves, but I do source-control a template configuration file, with all the parameters and their default values, and comments describing what they do. For example, if a configuration file is named
database.conf
, I usually source-control a file nameddatabase.conf.template
. Now of course I am talking about what I do as a developer. As an admin, I may want to source-control the actual settings that I chose for each installation. For example, we manage a few hundred servers remotely, and we need to keep track of their configurations: we chose to do this with source-control.Edit: Although I believe the above to be true for most applications, there are always exceptions, of course. Your application may allow its users to dynamically configure complex rules, for example. Most email clients allow the users to define rules for the management of their emails (for example, "all emails coming from 'john doe' and not having me in the To: field should be discarded"). Another example is an application that allows the user to define a new complex commercial offer. You may also think about applications like Cognos which allow their users to build complex database reports. The email client will probably offer the user a simple interface to define the rules, and this will generate a complex configuration file (or even perhaps a bit of code). On the other hand, the user-defined configuration for the commercial offers might be saved in a database, in a structured way (neither a simple key=value structure nor a portion of code). And some other applications might even allow the user to code in python or VB, or some other automation-capable language. In other words... your mileage may vary.
好的。 您将有一些用户想要一个非常简单的配置,您应该将其提供给他们。 同时,您会不断收到“您可以添加这个吗?我在配置文件中该怎么做?”的请求,我不明白为什么您不能支持这两个组。
我目前正在做的项目使用Lua作为其配置文件。 Lua是一种脚本语言,在这种情况下效果很好。 我们提供了默认配置的示例。
你会注意到它主要是 key=value 语句,其中 value 可以是 Lua 的任何内置类型。 最复杂的东西是列表,它们实际上并不复杂(这只是语法问题)。
现在我只是在等待有人询问如何在每次启动时将服务器的端口设置为随机值......
Ok. You will have some users which want a really simple config, you should give it to them. At the same time, you will have constant requests of "Can you add this? How do I do in the config file?", I don't see why you can't support both groups.
The project I am currently working on uses Lua for its configuration file. Lua is a scripting language, and it works quite well in this scenario. There is available an example of our default configuration.
You'll note that it is mainly key=value statements, where value can be any of Lua's built-in types. The most complicated thing there are lists, and they aren't really complicated (it's just a matter of syntax).
Now I'm just waiting for someone to ask how to set their server's port to a random value every time they start it up...
最近,我正在开发一个项目,我意识到我想在我的配置文件中包含条件 - 以前只是一个非常简单的形式:
我不想编写一种迷你语言,因为除非我这样做非常小心地我不能允许有用的灵活性。
相反,我决定采用两种形式:
如果文件以“#!”开头 并且是可执行的,我会解析运行它的结果。
否则我会按原样读取它
这意味着我现在可以允许人们编写如下所示的“配置文件”:
这样,如果用户想要使用动态配置文件,我就可以获得动态配置文件的强大功能,并且无需编写自己的迷你语言,也很简单。
Recently I was working upon a project and I realised that I wanted to have conditionals inside my configuration file - which had previously just been a pretty simple one of the form:
I didn't want to write a mini-language, because unless I did it very carefully I couldn't allow the flexibility that would be useful.
Instead I decided that I'd have two forms:
If the file started with "#!" and was executable I'd parse the result of running it.
Otherwise I'd read it as-is
This means that I can now allow people to write "configuration files" that look like this:
This way I get the power of a dynamic configuration file if the user wants to use it, and the simplicity of not having to write my own mini-language.
每个(足够长的)配置文件模式最终都会成为一种编程语言。 由于您所描述的所有含义,配置文件设计者明智地意识到她正在编写一种编程语言并相应地进行计划,以免给未来的用户带来不良遗产的负担。
Every (sufficiently-long-lived) config file schema eventually becomes a programming language. Due to all the implications you describe, it is wise for the config-file designer to realize she is authoring a programming language and plan accordingly, lest she burden future users with bad legacy.
我对配置文件有不同的看法。 有关应用程序应如何运行的数据仍然是数据,因此属于数据存储,而不是代码(IMO 中的配置文件是代码)。 如果最终用户需要能够更改数据,那么应用程序应该提供一个接口来执行此操作。
我只使用配置文件来指向数据存储。
I have a different philosophy about config files. Data about how an application should be run is still data, and therefore belongs in a data store, not in code (a config file IMO is code). If end users need to be able to change the data, then the application should provide an interface to do so.
I only use config files to point at data stores.
您可以求助于计算理论来定义什么才是编程语言。 如果您的配置文件格式是图灵完备,那么它就可以合理地算作一种编程语言。 根据这个定义,描述 Sokoban 级别的文件格式算作一种编程语言(请参阅< a href="http://web.cs.ualberta.ca/~joe/Preprints/Sokoban/index.html" rel="nofollow noreferrer">此处)。 图灵完备以下的其他复杂程度也可能算在内,例如 正则语法 和 < a href="http://en.wikipedia.org/wiki/Pushdown_automaton" rel="nofollow noreferrer">下推自动机。
另一种看待它的方式是,许多配置文件只能进行数据标记,而正确的编程语言必须能够实现 算法。 例如,JSON 是一种配置文件格式,而 ECMA Script 是一种编程语言。
You could turn to theory of computation to define what counts as a programming language. If your configuration file format is Turing Complete then it reasonably counts as a programming language. By this definition, a file format to describe levels of Sokoban counts as a programming language (see here). There are other levels of complexity below Turing Complete that may also count, such as Regular Grammars and Pushdown Automata.
Another way to look at it is that many config files are only capable of data markup, whereas a proper programming language must be able to implement algorithms. For example, JSON is a config file format, whereas ECMA Script is a programming language.
这是我的想法:
允许轻松修改应用程序的运行时行为。 这可以由程序员或非程序员完成,具体取决于需要。 这可以在开发过程中进行,但我经常将配置文件视为帮助程序在任何时候变得更加灵活的一种方式。
是的。 我认为配置文件应该尽可能简单,因为您可能需要各种选项来控制运行时的不同行为。 我更喜欢对配置设置进行分组,并尽可能地简化它们。
取决于进行更改的内容和原因。 如果用户要更改它,应该创建一个前端来隐藏他们的细节。 对于一般非开发人员来说也是如此。
我经常对“默认”配置进行源代码控制,但有一种方法可以在实际运行时覆盖每个系统的此配置。
至于向配置文件添加逻辑 - 我会避免这种情况。 我认为最好让配置文件在应用程序中切换逻辑。 根据我的经验,配置文件中的行为会导致缺乏可维护性和理解。 我强烈喜欢使配置文件尽可能简单。
Here's my thoughts:
To allow the runtime behavior of an application to be modified easily. This can be by programmers or non programmers, depending on the needs. This can be during development, but I often view configuration files as a way to help make a program more flexible at any point.
Yes. I think config files should be as simple as possible, given the constraint that you may need various options to control different behaviors of your runtime. I prefer grouping configuration settings, and simplifying them as much as possible.
Depends on what and why the change is being made. If users are going to be changing it, a front-end should be made to hide them from the details. The same is often true of non-developers in general.
I often source control the "default" configuration, but have a way to override this per system for the actual runtime.
As for adding logic to the config file - I'd avoid this. I think it's better to just have the configuration file switch on the logic in your application. Behavior in config files leads to a lack of maintainability and understanding, in my experience. I strongly prefer keeping configuration files as simple as possible.
我倾向于同意这个问题的前提。 我通过尽早预测这将会发生来避免给自己带来麻烦,因此从不推出我自己的配置系统。
并接受我所做的任何决定,或者如果我不能,重构以使用上述更适合应用程序的选择之一。
重点是,实际上没有任何理由使用本土的配置解决方案。 一方面,您的用户更难学习新的、特定于应用程序的配置格式。 另一方面,使用现成的解决方案时,您可以从免费的所有错误修复和更新中受益。 最后,功能蠕变被搁置了,因为,好吧,你实际上不能在没有真正进行重大修改的情况下添加一个功能,因为配置系统一开始并不真正掌握在你的手中。
I tend to agree with the premise of this question. I avoid getting myself into trouble by predicting early that this is going to happen, and therefore never roll my own config system.
And resign myself to live with whatever decision I made, or if i cant, refactor to use one of the above choices that better suits the application.
Point is, there's not really any reason to use a home-grown config solution. For one thing, it's harder on your users to have to learn a new, application specific config format. For another, You benefit from all the many bug-fixes and updates that come free when using an off-the-shelf solution. Finally, Feature creep is put to rest, because, well, you actually can't just add one more feature without really doing a major overhaul cause the config system isn't really in your hands in the first place.
这取决于您与团队中其他开发人员的共识。 您是像配置文件一样使用配置文件还是正在创建模型驱动应用程序。
配置文件成为编程语言的症状:
It depends on what you agree with other developers on the team. Are you using config files just as config files or you are creating a Model Driven application.
Symptoms of config file becoming a programming language:
配置文件总是慢慢地变得丑陋、不合逻辑的“成熟的编程语言”。 设计好的编程语言需要艺术和技巧,而配置语言变成的编程语言往往是可怕的。
一个好的方法是使用设计良好的语言,例如 python 或 ruby,并使用它来创建 DSL 适合您的配置。 这样,您的配置语言表面上可以保持简单,但实际上是成熟的编程语言。
Config files invariably inch their way to becoming ugly, illogical "full fledged programming languages". It takes art and skill to design good programming languages, and config languages turned programming language tend to be horrendous.
A good approach is to use a nicely designed language, say python or ruby, and use it to create a DSL for your configuration. That way your configuration language can remain simple on the surface but in actually be the full fledged programming language.
我相信考虑到向“流畅的界面”的转变,你的问题非常相关。 许多开发人员已经“看到了 XML 配置应用程序的曙光”。 使用 XML 可能非常冗长并且难以正确编辑(特别是在未提供架构的情况下)。 拥有流畅的界面允许开发人员借助纯文本配置文件(或者可能是命令行参数)中的一些键值对的帮助,以特定于域的语言配置应用程序。 它还使得设置和配置应用程序的新实例以进行测试或其他操作变得非常容易。
以下是我对您问题的回答:
文件?
配置文件是一种允许用户在运行时自定义程序行为的方法。
配置文件简单吗?
理想情况下,我认为配置文件至少应该辅以流畅的界面来配置程序(这在很多方面都很有用)。 如果您确实需要配置文件,那么它应该保持非常简单,只不过是键值对。
对他们的改变(开发者、用户、
管理员等)?
我认为这个问题的答案取决于您的组织。 部署软件的人员有责任确保其配置正确。
问题3)?
我将从其他人那里窃取这个答案:) 我喜欢在源代码管理中存储模板配置并根据每个本地用户的需求修改它的想法。 一个开发人员的配置文件很可能是另一个开发人员的噩梦,因此最好将因用户而异的内容置于源代码控制之外。 拥有模板也是让部署应用程序的人员(或其他开发人员)准确了解配置文件有效值的好方法。
I believe your question is very relevant given the move to "fluent interfaces". Many developers have "seen the light" with respect to XML configured applications. Using XML can be very verbose and difficult to edit correctly (especially if no schema is provided). Having a fluent interface allows the developer to configure the application in a domain-specific language with the assistance of some key-value pairs from a plain text configuration file (or perhaps command-line parameters). It also makes it very easy to setup and configure new instances of the application for testing or whatever.
Here are my answers to your question:
file?
A config file is a way to allow the user to customize the behavior of their program at run-time.
config files simple?
Ideally, I would think that config files should at least be supplemented by a fluent interface to configure the program (this is useful in many respects). If you do require a config file then it should be kept very simple, nothing other than key-value pairs.
changes to them (developers, users,
admins, etc.)?
I think the answer to this depends on your organization. It should be the responsibility of the person deploying the software to ensure that it is properly configured.
question 3)?
I will steal this answer from someone else :) I like the idea of storing a template configuration in source control and modifying it for each local user's needs. Chances are one developer's config file is another developer's nightmare so it is best to leave things that vary by user out of source control. Having a template is also a nice way to let the person deploying the application (or other developers) see exactly what values are valid for the config file.
我见过 python 程序,其中配置文件是代码。 如果您不需要做任何特殊的事情(条件等),它看起来与其他配置样式没有太大不同。 例如,我可以创建一个文件
config.py
,其中包含以下内容:与(例如)INI 文件相比,用户的唯一负担是它们需要在字符串周围放置 '' 。 毫无疑问,您可以用其他解释语言做同样的事情。 它使您可以在必要时无限地使配置文件复杂化,但可能会吓到用户。
I have seen python programs where the config file is code. If you don't need to do anything special (conditionals, etc.) it doesn't look much different from other config styles. e.g. I could make a file
config.py
with stuff like:and the only burden on the user, compared with (say) INI files, is that they need to put '' around strings. No doubt you could do the same thing in other interpreted languages. It gives you unlimited ability to complicate your config file if necessary, at the risk of possibly scaring your users.
是的,配置文件应该很简单。 它们本身不应该包含“逻辑”——将它们视为 if 语句中的表达式列表,而不是整个条件语句。
它们允许用户决定应该使用应用程序中编码的哪些选项,所以不要试图使它们复杂化,这最终会弄巧成拙 - 您最终可能会编写简单的配置文件控制原始配置文件的配置方式!
Yes, config files should be simple. They should contain no 'logic' themselves - think of them as a list of expressions in if statements, not the conditional statements in their entirety.
They're there to allow the user to decide which of the options coded within the application should be used, so don't try to make them complicated, it'll end up being self-defeating - you may end up writing simple config files to control how the original config file should be configured otherwise!
Microsoft 的“奥斯陆”工作的目的之一是允许(但不要求)解决此问题。
这意味着相当于当今的配置文件可能足够丰富以支持其配置的文本和图形编辑。 图形工具将随“Oslo”(代号“Quadrant”)一起提供。
One of the purposes of the "Oslo" work at Microsoft is to permit (though not require) resolution of this issue.
This means that the equivalent of todays configuration files may be rich enough to support both textual and graphical editing of their configuration. The graphical tool will be supplied with "Oslo" (code name "Quadrant").
我会持相反观点,认为它只是一种语言,因为它所体现的内容超出了 XML 所能表示的范围。 或者当 XML 被认为是一种语言时。
或者,大多数配置文件可以被视为类,但只有属性而没有方法。 如果没有方法,我不认为它是一种语言。
归根结底,“语言”是一个模糊的抽象概念,但是,边缘是模糊的。
I'll be the contrarian and submit it's only a language when it embodies more than can be represented by XML; or else when XML is considered to be a language.
Alternatively, most config files can be thought of as classes, but with only properties and no methods. And without methods, I don't think it's a language.
Ultimately, "language" is a squishy abstraction, but yes, the edges are ambiguous.
我们的应用程序的代码变得不那么重要了......有脚本,有各种定义类、方法、方法参数和属性的行为的属性。 用户可以定义数据库触发器和数据库约束。 可能有非常复杂的配置文件。 有时,用户可以定义 XSLT 样式表来操作输入和输出,因为我们的系统需要开放(SOA)。 还有像 BizzTalk 这样的东西也需要复杂的配置。 用户可以定义复杂的工作流程。
我们必须编写更好的代码来应对这种复杂的环境,因此我们应用程序的代码变得更加重要......
The code of our applications becomes less important... There is scripting, there are all kind of attributes that define the behaviour of classes, methods, method arguments and properties. Users can define database triggers and database constraints. There can be very complicated config files. Sometimes the user can define XSLT stylsheets to manipulate input and output because our systems need to be open (SOA). And there is stuff like BizzTalk that needs complex configuration too. Users can define complex workflows.
We have to write better code to deal with this complex environment, so the code of our applications becomes more important...
我非常喜欢使用 python 程序作为配置文件,尤其是守护进程。 我喜欢采取的策略是让守护进程完全没有配置,除了“配置端口”之外。 然后,Python 程序连接到守护进程,并继续在守护进程中创建对象,并将它们连接在一起以创建所需的配置。 一旦一切设置完毕,守护进程就可以自行运行。 当然,这样做的好处是,您可以获得一种成熟的编程语言来编写配置文件,并且由于您已经有一种方法可以从另一个程序与守护进程对话,因此您可以使用它来调试和获取统计信息。 主要缺点是必须处理随时来自另一个程序的消息。
I'm a big fan of using python programs as config files, especially for daemons. I like to take the tack of making the daemon completely empty of configuration except for the "configuration port". The python program then connects to the daemon and proceeds to create objects in the daemon and wire them together to create the desired configuration. Once everything is set up, the daemon can then be left to run on it's own. The benefits, of course, are that you get a full fledged programming language to write your config files and since you already have a way to talk to the daemon from another program, you can use it for debugging and getting stats. The major downside is having to deal with messages from another program coming in at any time.
配置文件:“我的目的是什么?”
你:“配置黄油。”
配置文件:“好的...”
配置文件:“我的目的是什么?”
你:“你配置黄油。”
配置文件:“天哪。”
你:“是的,欢迎来到俱乐部。”
配置文件没有“真正的目的”。 它对您的应用程序有意义。 一般来说,机器之间不同(或可能不同)并且在应用程序运行过程中不会改变的东西可能应该在配置文件中。 其他服务的默认值、端口和地址都是不错的选择。 密钥和秘密也是很好的选择,但出于安全原因应与正常配置分开处理。 我不同意配置文件的目的是允许快速更改。 目的应该是允许应用程序设置的灵活性。 如果配置文件是一种快速简单的方法来实现这种灵活性,那就更好了 - 但您不应该希望您的配置文件经常更改。
是和否。 您是否应该尝试使应用程序的代码变得简单? 是的。 您应该尝试使您所写的所有内容简单明了。 不需要比需要的更复杂。 您的配置也是如此。 然而,这是非常特定于应用的。 对配置中应包含的内容进行硬编码是糟糕的设计,因为这会使您的配置“过于复杂”。 事实上,试图“让事情变得简单”就是配置文件最终变得一团糟的原因。 有时,最简单的举措就是模块化。 这就是为什么你的配置文件应该用众所周知的通用编程语言编写 - 而不是一些糟糕的配置语言(阅读:所有“配置语言”都很糟糕)。
同样,谁应该修改配置文件完全取决于应用程序。 但我同意 miniquark 的观点,无论谁部署应用程序都应该负责配置。
尽你所能控制源代码。 源头控制很棒。 您可以非常轻松地回滚内容,并且您拥有所做更改的完整历史记录以及进行这些更改的人员的记录。 那么为什么不呢?
Config file: "What is my purpose?"
You: "Configure the butter."
Config file: "Ok..."
Config file: "What is my purpose?"
You: "You configure butter."
Config file: "Oh my god."
You: "Yeah, welcome to the club."
There is no "true purpose" of a configuration file. Its whatever makes sense for your application. In general, things that differ (or might differ) between machines and don't change in the middle of your application run should probably be in a configuration file. Defaults, ports, and addresses for other services are all great candidates. Keys and secrets are also great candidates but should be handled separately from your normal config for security reasons. I disagree that the purpose of a config file is to allow quick changes to be made. The purpose should be to allow flexibility in the setup of your application. If a config file is a quick easy to way to allow that flexibility, so much the better - but you should not be intending your config files to be frequently changing.
Yes and no. Should you atempt to make your application's code simple? Yes. You should attempt to make everything you write simple and to the point. No more complicated than it needs to be. Same is true of your config. However, this is very application specific. Hardcoding what should be in config because it would make your config "too complicated" is bad design. In fact, trying to "keep things simple" is why config files end up being a giant mess. Sometimes the simplest move is to modularize. This is why your configuration files should be written in a well known general purpose programming langauge - not some terrible configuration language (read: all "configuration languages" suck).
Again, who should be modifying config files is completely application dependent. But I agree with miniquark, whoever is deploying the application should be in charge of the configuration.
Source control everything you can. Source control is great. You can roll stuff back super easily and you have a full history of the changes you've made and a record of who made those changes. So why not?
将条件逻辑保留在程序中,并将数据/参数保留在配置文件中。 简单的人!
Keep conditional logic in your program and data/params in your config file. Simples people!