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 == ' ', ...)
>
> which becomes:
>
> sm = difflib.SequenceMatcher(isjunk=x == ' ' with x, ...)
>
> The expression x==' ' doesn't look like a function to me.

Hold that thought.

>> Ideally, we could move that noise out of the way so that the intent
>> is more clearly expressed:
>
> So you say.
>
> I say it isn't noise, and if you ask me to express my intent, I'll
> state that it is a function first and at the beginning of the
> expression, not the end.

Okay, so I'm trying to follow along, and not jump in with another "me,
too" response.

Statements and expressions don't read from left to right.

Blocks and functions don't read from top to bottom.

Some people read programs from the inside out, assembling bigger and
bigger building blocks until the entire program is just a building
block.  Others read programs from the outside in, decomposing really blg
blocks until the remaining blocks are small enough to see and understand
without further decomposing.

Reading a program, let alone figuring out what it does, let alone
figuring out what it's supposed to do, is not a simple single pass
process.  Something has to come first, and something has to come next,
and something will end up coming at the end.  Regardless, the reader
will have to save some context, or go back and look at the beginning
again.

So is it better to see the definitions first, and the logic second?  Or
is it better to see the logic first and the definitions later?  I don't
know; it depends.  It may even vary over time inside the same code base.

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.  :-/

A large part of my previous job was digesting papers written by
economists and mathematicians, and then translating the ideas and
algowithms in those papers into code.  Sometimes, I'd see stuff like
this:

    Given x = the width of a widget and y = the price of that widget,
    let f(x, y) be x + y.

And sometimes, even in the same paper, I'd see stuff like this:

    Let f(x, y) be x + y, where x = the width of a widget and y = the
    price of that widget.

Which one is harder to read, or expresses the intent better?  If that's
what we're down to, then an assignment operator is a trivial exercise.

Dan

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

Reply via email to