Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
>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:
>
>
What difference does braketing possibly make? Either way, internally,
the language works the same. You could, and I've seen it done, modify
Python to use braces and it changes absolutely nothing in the languages
behavior.
>{
> $i = 1;
>
> sub counter {
> $i++;
> }
>}
>
>Or actually, why that wouldn't be done in Python as
>
>i=1
> def counter()
> i = i+1
>
>
You can do that, to a limited degree, but why would you want to. It's
bad program design. You should use an object to define scope or just use
explicit variable passing to the function. Besides, Python has
generators specificlly for tasks like that.
>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.
>
Python wants you to use objects or explicit variable passing. Everything
is an object. Which is why even global variables aren't really global..
they are just within the current file. Python makes a lot of effort to
keep you from making a mess of your code and that includes making it
hard to define crazy scoping of variables. You also have to learn to
make use of Python's concept of modules which help define the scope of
things. You don't just declare large chunks of code in a single file.
The sepperation of code into different files is an important part of the
language. As to why you'd want to define i as local to a function,
outside of that function, I have no idea.
>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.
>
>
Python has blocks that work exactly as if you were using braces.. only
without the braces. It's really no better or worse than using braces
IMO. A little cleaner looking I think but nothing else.
>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.
>
>
The only reason to use line continuation devices in Python is to keep
with Unix tradition. Usually the code will run just fine without those
devices.. Again though, there is an effort to keep you from making crazy
long lines. That's bad coding style, which I'm as guilty of as anyone,
and hurts maintainability.
>(Snip rest; I never used PHP once I saw it's dorkiness.)
>
>
PHP is dorky but works well for what it was meant for.
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members