Python as first language (Re: static variables?)

Hung Jung Lu hungjunglu at yahoo.com
Wed Nov 20 14:19:03 EST 2002


On Tuesday 19 November 2002 11:37 am, Michele Simionato
<mis6 at pitt.edu>
wrote in comp.lang.python:
> A simple trick to simulate static variables by passing an optional
> mutable object is the following:
> 
> def f(x,i=[0]): # i[0] is the "static" variable
>     i[0]+=1
>     return x+i[0]
> 
> print f(0),f(0),f(0) #--> 1,2,3

Erik Max Francis <max at alcyone.com> wrote in message news:<3DDB3373.2578CEC0 at alcyone.com>...
> Oh, of course; there's really no question why this is the case in the
> current implementation.  My point is that there is no real a priori
> reason why mutable default arguments couldn't do the equivalent of
> 
> 	def f(x=None):
> 	    if x is None:
> 	        x = SomethingMutable
> 	    ...
> because it's the easiest obvious implementation -- but there's no reason
> in and of itself that it _must_ be done that way.

Sorry for digressing, but this reminds me of an old debate on whether
Python is suitable as the first language to teach.

Well, the thing is that Python works with "name binding". And the
concepts of name spaces, name binding, objects, mutability, etc. are
just a bit non-obvious. Once a person understands these things, or if
a person knows about pointers, hashmaps and memory structure,
everything becomes clear. But for someone not familiar with either of
these sets of concepts, Python can be hard to explain.

After many years in the Python world and having seen so many debates,
I still have to say that Python is not good as the first programming
language to teach.

>From the perspective of someone who is in the working world, I'd like
to see Python being taught in colleges/universities, but not as the
first language. Rather, I'd imagine some sort of Python workshop
course, where students are assigned different topics, and then do some
presentations to the class. Python is valuable as a door opener to
many fields in modern software development. But I have my reservations
about its suitability as the first language to learn. Maybe it's just
me, but I have been horrified by programmers writing a few lines of
code, without realizing their few lines of code can actually have
severe impact on the RAM or the harddrive. I still feel more
comfortable if the new generation of programmers starts with a
language closer to the machine level, where one can kind of "feel" the
bits and bytes. Just my 2 cents. :)

Hung Jung



More information about the Python-list mailing list