[Python-ideas] Does jargon make learning more difficult?

Steven D'Aprano steve at pearwood.info
Wed Aug 22 02:11:54 EDT 2018


On Tue, Aug 21, 2018 at 01:56:16PM -0500, Abe Dillon wrote:

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


widget.register(value[a](x)                     with x)

(As per your earlier example of ternary if operator, I've inserted 
spaces to emphasis the gap.)

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.

Even Forth, which (apart from its use of extremely concise commands) is 
most (in)famous for backwards things writing in Reverse Polish Notation, 
or programming by Yoda *wink* nevertheless puts the "function 
declaration" before the body. Classically, you define a function like this:

    : func DUP DROP ;

The colon tells the interpreter to start compiling a function named 
"func", DUP and DROP are the commands in the body of the function (in 
this case, a pointless combination), and the semi-colon says to stop 
compiling and bind the new function body to the given name.

Classical Forth doesn't have named function parameters, but some RPN 
languages do, and likewise they come first. In the HP calculator RPN 
language, we write something like:

    << -> x << DUP DROP >> >>

to grap an argument and assign it to "x".

Given some sort of look-ahead, it's *possible* to put the parameter list 
at the end of the function body:

    def function:
        do_this(a)
        do_that(b)
        do_something_else(c)
   with (a, b, c=None)

but I think you can see why that would be annoying. You don't even know 
which names are global and which are parameters until you get to the 
very end of the function. Blah.

The same applies to function expressions. Given the function body:

    value[a](x)

which of value, a and x are global names and which are parameters?

> If you don't know what that parameter is, then that's where the
> "wait wait wiat!" should happen. 

"Wait wait wait!" should ideally never happen. In programming, surprises 
are not a good thing, and they're even less good when they are 
retroactive. 

"Ha, fooled you! You thought you were dealing with an eagerly evaluated 
expression, but it was a deferred function body declaration instead! 
Mwahahahaha!!!"



-- 
Steve


More information about the Python-ideas mailing list