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

后端 未结 18 1750
清酒与你
清酒与你 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:55

    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:

    
    key = val
    key2 = val
    name = `hostname`
    
    

    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:

    1. If the file started with "#!" and was executable I'd parse the result of running it.

    2. Otherwise I'd read it as-is

    This means that I can now allow people to write "configuration files" that look like this:

     #!/usr/bin/perl
    if ( -x /bin/foo ) 
    {
       print <

    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.

提交回复
热议问题