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, 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?
Of course you need to define i as global to see outside the function
scope.
If this was PHP you would see "i=0" and no error. Is that the desired
behaviour?
(Note: from here follows PHP v. Python ranting. Sorry Perl lovers, I
don't have enough experience in your language to do it justice... )
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.
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. Of course, this means you need a real editor to work with
blocks of code, so those of you using 'ed' may be disadvantaged, but
for normal people it makes reading and writing the code much easier.
Also, Python has list datatypes nicely integrated into the language.
I recently had the misfortune to translate an algorithm from Python to
PHP. (Nothing too hard, just text-wrapping and justifying). It grew
from half a screenful to several screens in size in the translation,
mostly because PHP requires you to call a function for every array
manipulation. Also, the code went from being reasonably readable
(choose your variable names wisely and Python reads like pseudocode)
to being a big mess of nested function calls and $ signs and ; { }
etc.
Python is easy to develop algorithms on because of its interactive
command-line. Maybe because I leaned to program on the Commodore
(Microsoft Basic V2.0), but the fastest way for me to choose a test
case, develop something by interacting with the interpreter until I
get something working, then paste the successful code into my script.
Even when I need execution speed (e.g. MPEG processing) I prefer to
develop my algorithm in Python, then convert to C later. It's _that_
much easier to debug and try different ways of doing something.
Regards,
Mark
EMAIL:PROTECTED
--
To invent, you need a good imagination and a pile of junk. -Thomas Edison
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members