[Python-ideas] Does jargon make learning more difficult?
Steven D'Aprano
steve at pearwood.info
Wed Aug 22 13:44:07 EDT 2018
On Wed, Aug 22, 2018 at 12:11:40PM -0500, Abe Dillon wrote:
> [Steven D'Aprano]
>
> > > The revelation that it's a function should come when you read the "by" or
> > > "key".
> > I disagree. The most important fact is that it is a function, not
> > specifically what it does.
>
>
> I was trying to say that the context almost always gives away that the
> reader should expect a function.
>
> Again, the pseudo code:
>
> hand = sorted(cards, by=card.suit)
>
> Is usually enough for most people to understand.
You are judging that from the perspective of someone whose native
language makes it easy to say "sorted by foo" (for some value of foo).
We shouldn't judge syntax proposals just on the cases that are carefully
chosen to showcase them at their best. Especially not trivial cases.
Here is a line from the importbench tool in Python 3.5:
def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
Under your proposal, that becomes:
def bench(name, cleanup=None with ???, *, seconds=1, repeat=3):
except I'm not really sure what goes in the ??? for an empty parameter
list. But whatever it is, do you still think it is obvious that people
will recognise "None" to mean a function without having to backtrack?
And from the threading tests:
t = threading.Thread(target=lambda: None)
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.
> 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.
> > Consider:
> > widget.register(value[a](x) with x)
>
> > At first it looks like you are evaluating value[1](x) eagerly, right
> > there in the method call, and then you have to backtrack and change your
> > expectation about what you just read when you get to the end and see the
> > declarations.
>
>
> First, how is your example any worse that the delayed binding of generator
> expressions?
>
> widget.register(value[a](x) for x in things)
Who says its worse? I think they are equally as problematic. Many people
have trouble with comprehension syntax precisely because it breaks
left-to-right order.
I think we ought to be cautious about emulating that elsewhere.
--
Steve
More information about the Python-ideas
mailing list