At what point does a config file become a programming language?

后端 未结 18 1405
清酒与你
清酒与你 2021-01-29 18:27

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 mor

18条回答
  •  花落未央
    2021-01-29 18:51

    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:

    • What is the true purpose of a config file?

    A config file is a way to allow the user to customize the behavior of their program at run-time.

    • Should an attempt be made to keep 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.

    • Who should be responsible for making 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.

    • Should they be source controlled (see 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.

提交回复
热议问题