|
From: Robin M. <rob...@gm...> - 2006-06-06 01:37:42
|
On 5/23/06, Fuzzyman <fuz...@vo...> wrote:
> Hmmm... on the other hand I'm not convinced recursive interpolation is
> used by anyone. I don't mind it being dropped for the string templating
> interpolation - *if* that makes it any easier.
Seeing your blog post (where you mention that PEP-292-style substition
will be going into the next ConfigObj release) got me thinking about
recursive interpolation again. Right now the way it works is as
follows:
first = "one"
second = "$first plus one"
third = "$second plus one"
"third" is evaluated, yielding "$second plus one" -- which is then
further evaluated to yield "one plus one plus one". This is "lazy"
evaluation -- each string is only evaluated once its value is
requested.
What if this was changed to use "eager" evaluation instead, where each
string is evaluated as it goes past?
first = "one"
second = "$first plus one" -- immediately evaluated to yield "one plus one"
third = "$second plus one" -- immediately evaluated to yield "one plus
one plus one" (in one single step, since the value of $second is now
"one plus one" which needs no further recursive evaluation)
The advantage of lazy loading is that no particular order is enforced
on values. We could have written it in the order:
third = "$second plus one"
second = "$first plus one"
first = "one"
And it would have worked. That ordering would cause an error under
eager-evaluation, because "$second" is as yet undefined when "third"
is being created.
There's one other behavior of the interpolation that was surprising to
me: the fact that interpolated variables are *only* allowed to refer
to values in the [DEFAULT] section. That means that I can't do:
[my_program]
path = /home/rmunn/foo
configfile = ${path}/bar.txt
Instead, I have to do:
[DEFAULT]
path = /home/rmunn/foo
[my_program]
configfile = ${path}/bar.txt
This, IMHO, breaks the Principle of Least Surprise. This may be how
ConfigParser behaves, but is this behavior correct? I would suggest
that it isn't; that people writing config files are much more likely
to naturally write the first form than the second.
This may be two separate issues, though, so perhaps I should break the
second one out into its own thread.
--
Robin Munn
Rob...@gm...
GPG key 0xD6497014
|