On Thu, 23 Aug 2018 21:40:12 +1000, Steven D'Aprano wrote:

> On Wed, Aug 22, 2018 at 06:50:29PM +0000, Dan Sommers wrote:
>> On Thu, 23 Aug 2018 03:44:07 +1000, Steven D'Aprano wrote:
>> 
>> > On Wed, Aug 22, 2018 at 12:11:40PM -0500, Abe Dillon wrote:
>> 
>> > difflib tests include this call:
>> >
>> > sm = difflib.SequenceMatcher(isjunk=lambda x: x == ' ', ...)
> [...]
> 
>> When you talk about intent, I think about use cases.  In the difflib
>> code I quoted above, is the intent to define a function, or to
>> instantiate a SequenceMatcher?  Well, no, it's probably to compute some
>> sort of difference.  Instatiating a SequenceMatcher and defining isjunk
>> are details.
>> 
>> So you're both wrong.  :-P
>> 
>> Or you're both right.  :-/
> 
> In this case, "intent" could refer to (for example):
> 
> Should we accuse Fred Bloggs of plagarism or not?
> +- decide whether two documents came from the same source;
>   +- decide whether the diff between two text strings falls 
>      within some threshold;
>      +- initiate and use a SequenceMatcher object;
>         +- provide an isjunk predicate function;
>            +- implement a specific predicate function.
> 
> 
> Because we are talking about lambda syntax specifically, I didn't think 
> the higher hierachies of intent were relevant, so I didn't mention them. 
> I thought we could focus on the two relevant to the syntax we're 
> discussing:
> 
> Provide an isjunk predicate function;
> +- implement a specific predicate function.
> 
> and take the higher levels as given. Given those two levels, "Provide a 
> predicate function" is at a higher level than the implementation of that 
> predicate function.
> 
> I'm sorry if that wasn't clear.

Yes, the discussion is/was about lambda syntax, and about how quickly I
(or someone else) can recognize that isjunk is being defined as an
anonymous function.  Perhaps I missed that the larger context had
already been established.

To focus my argument within your clarification:  if I have all of that
context, then I don't have to parse the code to know that the isjunk
parameter is a function.

And if parsing the anonymous function gives you (the generic you) that
much trouble, then please break it out into a def statement instead.
Flat is better than nested.  IIRC, you push for named functions in all
but the most trivial cases anyway (and I tend to agree).

Dan

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to