Would Anonymous Functions Help in Learning Programming/Python?
pavlovevidence at gmail.com
Sat Sep 22 01:52:41 CEST 2007
On Fri, 21 Sep 2007 21:37:18 +0000, Cristian wrote:
> Although his learning experience has gone mostly smoothly, he's hit a
> lot of speed bumps with functions. Specifically, he's having trouble
> thinking of functions as first order data (don't worry, I haven't
> confused him with such terminology yet). He had a little trouble
> understanding that you can pass functions as arguments to other
> functions (e.g., passing a key to the list.sort method). He also had a
> little trouble grasping functions within other functions. Last but not
> least, he had trouble grasping methods in class declarations, especially
> the required self as the first argument (I'm sure he wasn't the first).
First of all, let me say that I think "functions as first class data" is
helpful, but not crucial, to programming in Python, and there are many
people who simply don't need the lesson. Especially someone like an
engineer (in the classical sense), who isn't building versatile software
packages, won't need to resort to functional programming much. For
straightforward tasks, like sorting lists with a custom ordering,
functional progamming merely a convenience, and can be done without.
So I'm -1 on syntactic changes to the language to support a pedagogical
use that's not crucially important.
Now, as for the more general question--How do you teach functional
concepts?--because some people do need to know it. I suspect it's one of
those things where there are two possibilities and not much in between.
1. The person gets it right away.
2. The person doesn't get it right away.
In the latter case, trying to teach it conceptually is probably
hopeless. Best thing to do is teach functional usage for certain use
cases. For instance, teach someone to define a function returning a key,
and have them use "key=myfunc" in list.sort--and not worry about why it
works. If they keep at it, eventually one of two things will happen.
2a. The person will have an "A ha! I get it now!" moment, and will
finally understand the concept.
2b. The person will never get it.
More information about the Python-list