Thoughts on language-level configuration support?

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Mon Mar 30 11:17:21 EDT 2009


On Mon, 30 Mar 2009 06:40:00 -0700, jfager wrote:

> I've written a short post on including support for configuration down at
> the language level, including a small preliminary half-functional
> example of what this might look like in Python, available at
> http://jasonfager.com/?p=440.
> 
> The basic idea is that a language could offer syntactic support for
> declaring configurable points in the program.

What's a configuration point? Where do I find them in my programs?



> The language system would
> then offer an api to allow the end user to discover a programs
> configuration service, as well as a general api for providing
> configuration values.

Why is an end user changing variables in my program?


> The included example implements the first bit and hints at the third,
> defining a function that looks up what variable its output will be
> assigned to and tries to find a corresponding value from a configuration
> source.  It's very preliminary, but I hope it gives a flavor of the
> general idea.

Not really. It would help if you explained what problem you are trying to 
solve, what people do now, and how what you suggest would make that 
easier. 

Having read your blog post, I'm going to take a wild stab at guessing 
what you mean:

* Programs often have variables which relate to user-configurable 
options. For example, a basic list files command might include something 
like this:

if sys.argv[1] == '-l':
    show_long_listing = True
else:
    show_long_listing = False
# ...
# much later...
for filename in directory():
    if show_long_listing:
        print "%s %s %s" % (permissions(), filename, date())
    else:
        print filename


* The current solution is for the program author to define the interface 
and the implementation separately. For example, in the above code 
snippet, the command line option '-l' is the interface available to the 
end user, while the variable show_long_listing is the implementation used 
to implement configuration options in the program.


* You propose to expose the variable show_long_listing and it's ilk 
directly to the user, presumable via some service which can interrogate 
the program, discover what "configuration variables" are available, and 
allow the user to stuff random values into them in the hope of getting 
new and exciting bugs^W behaviour.


* This is better than current solutions to the question of getting 
configuration options from the user, like getopt and similar, because... ?


* This would be better with syntactic support rather than a library or 
module because... ?



Am I close?



-- 
Steven



More information about the Python-list mailing list