[Edu-sig] Python Pedagogy

Dan Crosta dcrosta at sccs.swarthmore.edu
Fri Jul 21 20:17:05 CEST 2006


Gregor Lingl wrote:
> [...]
>
> class Turtle(Pen):
>      def square(turtle, l):
>          for i in range(4):
>              turtle.fd(l)
>              turtle.lt(l)


Maybe this isn't a problem for learning programmers (especially if you 
introduce it in the way you did for us just now) -- but I got confused 
at the lower case of 'turtle' being a stand-in for the conventional 
'self'. I guess in my mind, it's important that the self-reference be 
consistent across classes, to the point of almost acting as a keyword, 
just so that you can glance at a bit in the middle of a method and see 
what it's doing. Otherwise, it's ambiguous whether the symbol 'turtle' 
is 'self' or some other variable.


> alex = Turtle()
> bert = Turtle()
> chris =Turtle()
> 
> for turtle in alex, bert, chris:
>      turtle.square(l)

Using a more suggestive name like 'turtle' in place of 'self' might 
suggest that the name itself has some meaning, rather than its position 
as the first argument to the method -- especially if you repeat the name 
in the __main__ scope like you've done in the snippet above.

It's an interesting idea, for sure, I'm just not sure I can really wrap 
my brain around it without some major rewiring.

- d


More information about the Edu-sig mailing list