Could you please shed a little light on this? I'm genuinely curious.
Could you please shed a little light on this? I'm genuinely curious.
Python: dynamic (yet with soft-typing bolted on), interpreted (and quite slow due to GIL); worst package management story compared to all the alternative; "the Python way" is not my cup of tea, I hate significant whitespace, and have been burnt by the Python2->3 fiasco
I value portability and formal language spec with multiple implementations as being the most important for me, precisely because of the experience of loosing code bases due to language lock-in.
So far, I've come up with JavaScript as a meta-language, and running it on Node.js, browsers, and also compiling a subset of it into native code, but while JavaScript is a good enough practical language for small apps, the direction it is being taken to in ES6+ and HypeScript to become "more like Java" doesn't make it a non-terrible language for large apps IMO. Also, it doesn't satisfy my static typing criterion.
I don't want to defend the GIL, but that's not the reason CPython is slow. PyPy can be 100s of times faster, and it has a GIL too.
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.
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.
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?