lilypond-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: convertrules.py with decorator update for today's git


From: Han-Wen Nienhuys
Subject: Re: convertrules.py with decorator update for today's git
Date: Wed, 2 Jul 2008 00:45:37 -0300

I know what a decorator is - I'm sorry for thinking it didn't work,
but the code is a bit obtuse, and I got confused by

 return lambda f: conversions.append ((version, f, message))

which stores the conv function, but then will also redefine the conv
function to None.  Essentially it does

def dec(f):
    return None

@dec
def f(x):
    return 1

print f

=>

None


Can you document this more clearly so it does not look so strange?

Also the patch should look like a proper commit, with description
prepended and your name attached as author.


On Tue, Jul 1, 2008 at 8:03 PM, Wilbert Berendsen <address@hidden> wrote:
> Op woensdag 2 juli 2008, schreef Han-Wen Nienhuys:
>> I already wrote a comment about this before, but I strongly doubt that
>> this does anything useful.
>
> The useful thing is dat a conversion rule now forms a single entity: version,
> message and conversion function.
>
> The current structure of convertrules.py is a bit error-prone: the function
> definition comes first and then the conversions.append method adds the
> version, a pointer to the latest definition of 'conv' and a message the the
> conversions list.
>
> My proposal is to use a decorator (we're requiring Python 2.4 anyway) so the
> version a conversion function applies to is clearly connected with the
> function and the message it outputs.
>
>> Have you tested this at all?
>
> Yes: I verified that the decorator based code just builds the same list in the
> conversions variable as the old code by diffing the repr() output of both
> lists.
>
> This is just a proposal to make convertrules.py look better, more clear and
> probably a little bit easier to maintain. Because you wrote in your first
> answer "This is an excellent idea" I kept up maintaining it. If it gets
> rejected, no problem, the old code works equally well. But IMHO, using a
> decorator is a perfect fit for convertrules.py.
>
> To summarize: with a decorator a conversion rule is really a single entity:
>
> ------------snip-----------
> @rule ((1, 2, 3), _("convert foo to bar"))
> def conv(str)
>   str = str.replace('foo', 'bar')
>   return str
> ------------snip-----------
>
> in the old code, those are separated, and the conversion.append() command is
> repeated every time instead of hiding that implementation detail:
>
> ------------snip-----------
> def conv(str)
>   str = str.replace('foo', 'bar')
>   return str
>
> conversions.append(((1, 2, 3), conv, _("convert foo to bar")))
> ------------snip-----------
>
> best regards!
> Wilbert Berendsen
>
> --
> LilyKDE, LilyPond for KDE: http://lilykde.googlecode.com/
>



-- 
Han-Wen Nienhuys - address@hidden - http://www.xs4all.nl/~hanwen




reply via email to

[Prev in Thread] Current Thread [Next in Thread]