(no title)
excessive | 6 years ago
First some good: Python is amazing for how approachable it is. I've tried to teach (non-programmer, but smart) people I know other simpler programming languages, and it doesn't take. For some reason, when I show them Python it goes so much better. Despite the flaws, Guido and crew clearly got this part right. I don't think any other language makes new programmers feel comfortable so quickly.
Ok, for the bad:
Python is a very slow interpreter. If all you're doing is gluing together C/C++ libraries and invoking them from Python, it works just fine. However, my experience writing new algorithms in pure Python is that they run between 50 and 1000 times more slowly than nearly equivalent C.
Python exposed so much of its its internal implementation for making C extensions that the developers hands are practically tied when it comes to improving the implementation. If you look at the Python C API, you'll see most of the structs exposed and 100s if not 1000s of public functions. Important (and complicated) extension modules (such as Numpy) are now dependent on lots of the current implementation details. This is the reason that alternate implementations of Python (such as PyPy) can never really catch up to compatibility. Many other languages provide the same functionality for C extensions/plugins without the same exposure to all of the internals.
Python painted itself into some odd corners by not requiring variables to be declared. Most programmers are surprised by the behavior of this snippet.
a = 0
def doit():
print(a)
a = 1
doit()
doit()
Also, it doesn't happen a lot in my experience, but typos in variables names can be silent errors because it will just introduce a new variable. Similarly, they needed to add a "nonlocal" keyword for when you want to modify something outside your scope. Note, you don't need nonlocal to just read it though.If there was a "var" keyword required to declare a new variable, you wouldn't need global or nonlocal, you could catch more typos in variable names, and the program above would behave correctly.
There are other issues too, but this post is getting long already, and these are the some of the big ones to me.
tannhaeuser|6 years ago
This I can agree on. Had a great experience teaching Python to 8-9 year-olds. OTOH, teaching JavaScript to 12-13 year olds for light browser gamedev was a disaster.
sandov|6 years ago
Ok. I'll bite.
I get UnboundLocalError: local variable 'a' referenced before assignment
shouldn't it print 0 twice, since a is considered a global variable at the time print(a) gets called?
EDIT: If I delete print(a), then it prints 0 twice. What the hell?