Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Martin v. Löwis
I guess that's inevitable (given lambda's existence... and human nature;-) and about on the same plane as another hatefully redundant construct I find myself having to beat upon over and over in code reviews: if expression: result = True else: result = False return result vs

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Steven D'Aprano
On Sat, 3 May 2008 08:27:27 pm Nick Coghlan wrote: Samuele Pedroni wrote: I found only an example in my personal recent code: START = !-- *db-payload-start* -- END = !-- *db-payload-end* -- TITLEPATTERN = lambda s: title%s/title % s this three are later used in a very few .find()

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Steven D'Aprano
On Sun, 4 May 2008 01:24:54 am Alex Martelli wrote: On Fri, May 2, 2008 at 11:32 PM, Mike Klaas [EMAIL PROTECTED] wrote: ... Sorry, that was a bad example. It is obviously silly if the return value of the function is callable. ...and yet it's *exactly* what keeps happening to

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Antoine Pitrou
Steven D'Aprano steve at pearwood.info writes: I think you're exaggerating a tad here. Why would you be very confused when you see TITLEPATTERN() or foo(callback=TITLEPATTERN)? What else would TITLEPATTERN be but a callable when it's being used as a callable? The real problem is this

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Michael Foord
Terry Reedy wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression Visually I find the second form very ugly. The colon indicates to me that a new line is expected, and

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Raymond Hettinger
[Terry Reedy] Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression Though def-statements are usually the best way to go, there are some reasonable cases where the first form reads

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Alex Martelli
On Sun, May 4, 2008 at 3:31 AM, Raymond Hettinger [EMAIL PROTECTED] wrote: ... for k,g in groupby(iterable, key=lambda r: (r[0].lower(), r[5].lower())): ... lastname_firstname = lambda r: (r[0].lower(), r[5].lower()) for k, g in groupby(iterable, key=lastname_firstname): ... That

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-04 Thread Greg Ewing
Raymond Hettinger wrote: lastname_firstname = lambda r: (r[0].lower(), r[5].lower()) for k, g in groupby(iterable, key=lastname_firstname): ... That transformation adds clarity. Going further and creating a separate def-statement outside the current function would just move the relevant

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Mike Klaas
On 2-May-08, at 11:23 PM, Scott David Daniels wrote: Mike Klaas wrote: ... A common pattern for me is to replace an instances method with a lambda to add monitoring hooks or disable certain functionality: inst.get_foo = lambda: FakeFoo() This is not replacable in one line with a def (or

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Steven
On Fri, 2 May 2008 19:03:55 -0400 Terry Reedy [EMAIL PROTECTED] wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression [...] There are currently uses of named lambdas at

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Samuele Pedroni
Terry Reedy wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression The difference in the result (the only one I know of) is that the code and function objects get the

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Nick Coghlan
Alex Martelli wrote: On Fri, May 2, 2008 at 4:11 PM, Jesse Noller [EMAIL PROTECTED] wrote: +1 from me +2 from me -- of all abuses of lambdas, this one's the worst. What Alex said :) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Robert Brewer
Samuele Pedroni wrote: I found only an example in my personal recent code: START = !-- *db-payload-start* -- END = !-- *db-payload-end* -- TITLEPATTERN = lambda s: title%s/title % s this three are later used in a very few .find() and .replace() expressions in the same module. I suppose

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Samuele Pedroni
Nick Coghlan wrote: Samuele Pedroni wrote: I found only an example in my personal recent code: START = !-- *db-payload-start* -- END = !-- *db-payload-end* -- TITLEPATTERN = lambda s: title%s/title % s this three are later used in a very few .find() and .replace() expressions in the same

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Christian Heimes
Steven schrieb: Speaking as one of those some people, my position is that functions created with lambda are first-class objects the same as everything else in Python, and a rule that says You must not assign a lambda to a name, ever would be a terrible rule. PEP 8 is for the standard library

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Georg Brandl
Christian Heimes schrieb: Steven schrieb: Speaking as one of those some people, my position is that functions created with lambda are first-class objects the same as everything else in Python, and a rule that says You must not assign a lambda to a name, ever would be a terrible rule. PEP 8 is

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Alex Martelli
On Fri, May 2, 2008 at 11:32 PM, Mike Klaas [EMAIL PROTECTED] wrote: ... Sorry, that was a bad example. It is obviously silly if the return value of the function is callable. ...and yet it's *exactly* what keeps happening to lambda-happy programmers -- in production code as well as

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Nick Coghlan
Samuele Pedroni wrote: I found only an example in my personal recent code: START = !-- *db-payload-start* -- END = !-- *db-payload-end* -- TITLEPATTERN = lambda s: title%s/title % s this three are later used in a very few .find() and .replace() expressions in the same module. I suppose my

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-03 Thread Leif Walsh
On Sat, 3 May 2008, Brett Cannon wrote: On Sat, May 3, 2008 at 1:03 AM, Terry Reedy [EMAIL PROTECTED] wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression The

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-02 Thread Guido van Rossum
Agreed, I tend to pick these out of style reviews at Google. On Fri, May 2, 2008 at 4:03 PM, Terry Reedy [EMAIL PROTECTED] wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-02 Thread Jesse Noller
+1 from me On May 2, 2008, at 7:03 PM, Terry Reedy [EMAIL PROTECTED] wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression The difference in the result (the only one I know

[Python-Dev] PEP 8: Discourage named lambdas?

2008-05-02 Thread Terry Reedy
Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression The difference in the result (the only one I know of) is that the code and function objects get the generic name 'lambda'

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-02 Thread Mike Klaas
On 2-May-08, at 4:03 PM, Terry Reedy wrote: Some people write somename = lambda args: expression instead of the more obvious (to most people) and, dare I say, standard def somename(args): return expression The difference in the result (the only one I know of) is that the code and

Re: [Python-Dev] PEP 8: Discourage named lambdas?

2008-05-02 Thread Jeff Hall
+1 For what it's worth from a newbie ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com