Hacker News new | ask | show | jobs
by jkork 4481 days ago
patterns / tricks = language deficiencies

Wake me up when Python will support tail call elimination and will get rid of GIL. For now this language is no better than PHP.

5 comments

For TRE: http://neopythonic.blogspot.com/2009/04/tail-recursion-elimi...

For the GIL, there are alternative implementations of Python (Jython, IronPython, etc.)

Hm... Python only supports 1000 recursions? That seems unsafe. It seems like anyone who writes functional-style code will run the risk of a stack overflow.
Believe it or not, it's actually deliberate. And not that uncommon in other languages too. The only way you can realistially have 'unlimited' recursion is to use tail call optimisation, which is deliberaterly not implemented in python:

http://neopythonic.blogspot.co.uk/2009/04/final-words-on-tai...

Is Guido's take on it.

Essentially, as I understand it, his take is that massive recursion is confusing, and 'unpythonic'. And with the whole 'explicit is better than implicit' thing, I guess there is a point.

Some times recursion is the best/most obvious solution, and then it is a bit annoying to not have TCO, but you can usually work around it.

You can increase the recursion limit like this:

import sys

sys.setrecursionlimit(x)

Kind of a "hackish" way to do things but you can do it if you need to.

^Although I think the idea is that you shouldn't need to. Any recursive implementation can either be easily translated to work iteratively, or can be implemented in such a way that 1000 levels of recursion should be more than enough.

For example, 1000 levels of recursion is more than enough to count all the nodes in a binary tree unless the tree is extremely poorly balanced or inordinately large.

No better than PHP? That's more than a little ridiculous. Every language has shortcomings, and there's no silver bullet/perfect multitool that can or should be used for everything.

It's too bad it's apparently not good for... whatever it is you do. It is pretty great for some things, and having spent more than a few years with both Python and PHP, I can say without reservation that there is absolutely no comparison in terms of language quality.

> I suggest you are suffering from the Blub Paradox[0][1][2].

Writing some C will cure that disease, but the treatment has possible side effects, like carpal tunnel syndrome.

P.G. is right about PHP. This language is better than Python in various ways. For ex. it does not scare people away if you want to sell your project, because everyone and their grandma knows PHP. Most successful web pages (eg. FB) started out with PHP, not Lisp, C++, Python, Java, but PHP.
Every language has patterns or tricks, and every language has deficiencies, but these aren't the same thing at all.

It seems you have read some generic criticism of Python to copy from, and don't have much first-hand experience

There are only handful of language runtimes that got rid of GIL entirely. Namely JVM, .NET, and Rubinius. Other languages either use non-native threads or doesn't support threading at all. (E.g. Nodejs has no threading.)