Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
On Thu, 1 Apr 2004, Mark Rages wrote:
> On Thu, Apr 01, 2004 at 07:42:13PM +0000, EMAIL:PROTECTED
> > wrote:
> >
> > Oh, and did they ever fix the following?
> >
> > i=1
> > def f():
> > print "i=",i
> > i = i + 1
> >
> > f()
> >
> > Hint: It does not print "i=2".
>
> I don't get it. Why would you expect it to? If you don't understand
> Python's scoping rules you might expect "i= 1" but whence 2?
I noticed that typo as well. But nobody has every made it clear to
me why Python does not have true lexical scoping. My best guess was
that, lacking a non-white-space bracketing device, you just can't do
this:
{
$i = 1;
sub counter {
$i++;
}
}
Or actually, why that wouldn't be done in Python as
i=1
def counter()
i = i+1
# more stuff
> Of course you need to define i as global to see outside the
> function scope.
Except that *makes* i global. In a true closure, i is *local*. And
you're not seeing outside the function scope, you're seeing your
own lexical scope.
(Snip.)
> One of Python's biggest strengths, to me, is its explicit scoping.
> If you import library foo, you use functions out of it thusly:
>
> foo.function(args)
>
> This makes maintaining a large codebase much easier... you don't
> have to grep around and find where "function()" is defined. It is
> infinitely better than feeble languages (PHP, ahem) that only
> understand "include" directives.
But no different from Perl, which also lets you import just the
symbols you need in qualified or non-qualified namespaces.
> Python's other strengh is that it avoids needless punctuation like {
> or } or ; at the end of every statement or $ in front of every
> variable.
Except that that's not needless punctuation! OK, except for the
$var thing, which I will not defend.
Block structuring delimeters {} are (wait for it...) what give you
blocks. Blocks are good.
Statement delimiters are (wait for it again...) what give you
statements. Python would be just as good (actually, much BETTER if
it made these things explicit. It's been awhile, but when I found
that you often had to use line continuation devices in Python, I
thought "How quaint." It turns out that Python (at least then)
wasn't expression oriented but *statement* oriented. I guess you
could say "to each his own" but there were reasons why he hashed
this stuff out in the 70s and decided that expressions and blocks
were Good Things. This is NOT leading edge kind of stuff.
(Snip rest; I never used PHP once I saw it's dorkiness.)
jking
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members