On Fri, 02 Sep 2005 20:53:44 -0400, Peter Hansen <[EMAIL PROTECTED]> wrote: > Carsten Haese wrote: >> On Fri, 2005-09-02 at 16:46, Laguna wrote: >>>def expiration(year, month): >>> weekday = calendar.weekday(year, month, 1) >>> table = [19, 18, 17, 16, 15, 21, 20] >>> return table[weekday] ... > True, but do you find that more readable? If I saw that in code I was > maintaining I would likely rewrite it, probably to look a lot like the > first one (though likely with a more descriptive name than "table"... > maybe expirationTable?).
That doesn't explain anything, IMHO. What 'table' really is is a list of day-of-month candidates for the third Friday. For some pieces of code, I find that it's better to document what it /does/ than to try to document /how/ it does it. And maybe add a bunch of unit tests to /demonstrate/ that it seems to work. The next programmer can then choose to either (a) understand the code or (b) rip it out and replace it. I would leave the body alone, but rename the function 'third_friday_of_month', and do 'expiration = third_friday_of_month'. /Jorgen -- // Jorgen Grahn <jgrahn@ Ph'nglui mglw'nafh Cthulhu \X/ algonet.se> R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list