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: Wilbert Berendsen
Subject: Re: convertrules.py with decorator update for today's git
Date: Wed, 2 Jul 2008 01:03:23 +0200
User-agent: KMail/1.9.9

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/




reply via email to

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