Late-binding of function defaults (was Re: What is a function parameter =[] for?) (fwd)

Laura Creighton lac at openend.se
Thu Nov 19 18:00:24 EST 2015


Arrgh!

I got Ned Batchelder's email wrong.  Forgot the t.
(for somebody whose irc nick is nedbat.  )

sending this to him again.   warning any repliers that the
mail address is wrong....

apologies,
Laura


------- Forwarded Message

From: Laura Creighton <lac at openend.se>
Subject: Re: Late-binding of function defaults (was Re: What is a function
 parameter =[] for?)
In-reply-to: <87d1v5emhl.fsf at elektro.pacujo.net>
References: <CAPTjJmpwjWnF=d6mpgbKS1biVLoR4APutgyH0n9t6CJ=Kh4dCg at mail.gmail.com

In a message of Thu, 19 Nov 2015 22:57:10 +0200, Marko Rauhamaa writes:
>Laura Creighton <lac at openend.se>:
>
>> My experience says that the people who are confused want lists to
>> behave like tuples. period. i.e. they don't want lists to be mutable.
>
>I think it's simpler than that. When you have:
>
>   def f(x=[]):
>       y = []
>
>the first [] is evaluated when "def" is executed, while the latter [] is
>evaluated whenever "f" is executed. It's easy to be confused.
>
>
>Marko

Note: Ned Bachelder (who is probably reading this on python-list
anyway added cc on this mail, as if I am to discuss somebody, however
briefly, they deserve to hear about it.  Which may irritate him to
get 2 copies instead of one, but so it goes.  I am talking about
BartC as well, but since this is his thread, I assume he is here.)

Now back to what Marko said:

This is one of the times when it is nice to be dealing with children.
The whole notion of 'when def is executed' is not on their radar
at all.  It is all a matter of 'I write this, I want that'. :)

And with reasonable amount of authority from experience, I can
tell you that 'write it with round brackets not square ones'
makes the code *just work* for a large number of students who
only have a limited amount of patience for 'understanding 
what they are doing'.  They want to be able to do it first,
and have understanding come later (if at all).

This is the learning approach of 'training' as opposed to
'educating'.  And, for all that we _talk_ of 'educating our
children' -- what we really do, a whole lot of the time, is
train them.  The very basic skills of reading, writing (typing?) 
and arithmetic and foreign languages  need to be trained, and no
amount of understanding the theory behind such things will
ever directly translate into being able to do it.

Indeed, the best authority on the planet on 13th century French court
dances is a one-legged Frenchman, (whose name I now forget).
Although he has (or maybe had, he is likely dead by now, he lost
his leg in WW2) the education and the theory and the scholasticism, 
anybody with 2 legs, however ignorant, can dance the court dances
better. 

Sometimes you want to understand what you are doing.  Sometimes
you just want to do it.  And sometimes, well, the only real way 
to get an understanding of what you are doing is to do it more.
This is, in my opinion, Bartc's problem. He doesn't program in
python enough to understand it more.  He wants us to give him
a better theoretical understanding of Python, but for me, at 
any rate he is hitting the wrong audience.  And Ned Batchelder
is unlikely to help.  Both of us come from the practical end
of things, and write lessons and talks like the one ChrisA
recommended -- which is wonderful.  And how I wish I could 
write like that -- but they are aimed at telling a practical
python programmer 'now that you know how to do it, here is how
to understand what you do'.  And then, pedagogically, you can 
move to 'and now you understand what you have been doing, here
are some awesome cool tricks you can do to make your life easier
(and impress your friends, for a particularly nerdy set of
freinds).

I don't think that Ned works for the untrained python programmer.
And until Bart writes a bunch of code in python, for many weeks
or even months, I will not be able to help him, either.

But in my life, I end up teaching programming, often to some very
smart young people who are specialists at being trained. They want me
to train them, not educate them.  When you are 9 years old,
approaching all of life with the attitude of 'how do I get <anything>
to spit out the results I want' is enormously adaptive.

They have the opposite problem of BartC -- they want to be excellent
programmers without understanding anything, while he wants to 
understand everything before he knows how to write decent python code.

It's a pedagogical problem.

Laura
- -- 
https://mail.python.org/mailman/listinfo/python-list

------- End of Forwarded Message



More information about the Python-list mailing list