A short list of things I don’t like about Python
Agreed on every point, but I have to add a few things.
- No real metaprogramming is a big problem for me. I want decorators to be able to manipulate the AST (I'm playing around with a way to do this: http://pastie.org/490836 ) at the very least, and preferably real macros that can add new syntax.
- Anonymous functions. I want real anonymous functions in Python, not lambda or anything like it. After a long time of hacking Nemerle code, I go back to Python and cry when I write lambdas.
- Tail call recursion. Another functional programming thing that I'd absolutely love to see, just because it's so incredibly useful.
Sadly, I know none of these will likely be implemented, as they're just not the Python way, but it doesn't change the fact that I love Python and would love to see these changes.
The author makes the assertion that flat is better than nested, and indeed it's one of the rules in "import this", but I just don't see it. I spend about half my time in python, and about half in erlang. Erlang makes python look pretty deeply nested, since it pretty much lacks support for any namespace nesting, but honestly, I prefer Java's namespaces. If I were to write a library in Java (god forbid), I'd start it in net.tsuraan.whatever. I'd know that I'm not going to have namespace clashes with the standard library, apache, nor anybody else that is half-way sane. In python, the root namespace is pretty crowded, and you need to step carefully to avoid namespace clashes. In erlang, it's even harder. Why do people like flat namespaces, as opposed to reasonably nested ones?
Yay for another person like me who wants to be able to sprinkle just a little static-typing goodness back into the dynamic typing orgy everyone is having these days.
I don't mean huge cumbersone Java or C++-esque typing, just the simple ability to declare to the compiler (or to humans trying to read my code) - 'object foo is a Foo, please give me a hand and tell me if you can deterministically figure out that it is not, or if it is doing something that Foos are never allowed to do'.
This is a pretty minor thing compared to a lot of the warts here - to be honest, I'm not in the league of most of you as a programmer, I suspect - but two pretty simple things I've found surprising/annoying and have managed to shoot myself in the foot with:
* loops leaking their control variables: I get why this is useful sometimes, but it particularly bites with list comprehensions, especially as generator expressions don't leak. Apparently the list-comprehension part of this goes away in Python 3 (http://mail.python.org/pipermail/python-3000/2008-April/0131...).
* How mutable default argument values behave. Now, this one's even mentioned in the tutorial - http://docs.python.org/tutorial/controlflow.html#default-arg... - so I've really got no excuse, but that hasn't stopped me getting it wrong before!
Macros. Macros macros macros. Even if I can't have full-on lisp-y AST macros, I'd kill for relatively simple CPP-ish textual macros, just to cut down on boilerplate code.
Not that the chances are any good, and I can understand why - it would be decidedly un-Pythonic. But it's just mildly frustrating at times when I find myself writing the same coupe of lines of code twenty times within a file, because scoping rules insist they have to be there (reading from locals() is often where it hits me))
I think this whole "things I hate in $language" misses a very important point.
There is an immensely rich universe of languages you can chose from today. If you want Lisp-ish lambdas and macros, you should, by all means, go with Lisp. If you want to build your own DSL, you may as well chose Ruby. If you want pythonic indentation-as-structure, you should go with Python and, if you love the "do this if that" thing, you should consider Perl.
Having said that, I would love if Python threads had better support for multi-processors. It's not like changing syntax and turning Python into something it isn't, it's just properly implementing something that should be there from day 1.
Man, I was ready to reply with a nasty comment until I saw who the blog post was from. :-)
undefined
He forgot one: "Everything is a run-time error."