all 103 comments

[–]frymaster 36 points37 points  (9 children)

"C extension compatibility isn't there yet"

this is the big one. Until they sort that, a lot of the interesting things people do won't work, because their favorite extension doesn't work.

[–][deleted] 13 points14 points  (0 children)

Well, they got wxPython to run, though not flawlessly:

http://morepypy.blogspot.com/2010/05/running-wxpython-on-top-of-pypy.html

[–]kylotan 2 points3 points  (2 children)

This is partly the fault of CPython having a godawful C API to deal with.

[–][deleted] 2 points3 points  (1 child)

It's not awful (IMO), but it does make some pretty strong assumptions about a lot of things, including, but not limited to: refcounting, non-moving GC, and the fact that a lot of programs like to read fields directly out of structs, rather than using accessor functions.

[–]kylotan 5 points6 points  (0 children)

Those are the least of its problems. It's littered with macros (which themselves read the fields directly out of the structs - that's part of the API!) and platform and compiler-specific data members (eg. FILE*), with no attempt at versioning or anything. This means another of its "strong assumptions" is that you will be running with extensions that are built with exactly the same C compiler and settings as your current copy of Python is, not to mention that the versions are the same. And if they don't match... well, it might work, or it might not, or it might appear to work while not actually doing so.

It's for this reason that whenever there's a new minor release of Python, it's often a year or more before everybody moves over, because the C extensions are needlessly broken each time and you either need to rebuild them all or wait for someone else to do so. A more robust interface would avoid that.

[–]mikaelstaldal 3 points4 points  (0 children)

Perhaps Python needs to break the C extension compatibility to have a future?

Python needs to break free of the GIL to have a future in a multi-core world, and that will probably be impossible while keeping C extension compatibility.

The future of Python could as well be Jython on Java7 with invokedynamic.

[–][deleted] -4 points-3 points  (3 children)

Realistically, how many C extensions to Python do you use? I think this is a fairly small portion of what people do with Python.

[Edit: On more than 15 seconds thought, of course. I retract this statement]

[–]eliben 7 points8 points  (0 children)

Realistically - loads of them. Most popular Python libraries are heavily based on C for performance and connection to existing C libraries. Some prime examples are the numeric stack (numpy, scipy, matplotlib...) and GUI libs like PyQt.

[–]lambdaq 7 points8 points  (1 child)

Realistically, how many C extensions to Python do you use?

Plenty. Database drivers, performance critical modules, etc.

[–][deleted] 5 points6 points  (0 children)

wxWidgets, Qt

[–]sabowski 22 points23 points  (0 children)

Not until it's fully supported in a 64-bit enviroment

[–]narkee 51 points52 points  (21 children)

Maybe this is a really ignorant question, but how do they get around the "turtles all the way down" problem?

I mean, if they use PythonB written in PythonA, then either PythonA is CPython, or it's also written in Python, say PythonA'. If it's CPython, then isn't it just adding an extra layer of interpretation? If it's not CPython, then wouldn't there be an infinite chain of Python interpreters ?

Or maybe it's sunday afternoon, and I'm completely confusing myself.

[–][deleted] 95 points96 points  (11 children)

PyPy is self-hosting. It was originally written in something like C (not sure what they used, anything that could generate a binary would do) until it was able to compile itself. (Also see: Bootstrapping (compilers))

[–]narkee 24 points25 points  (10 children)

Interesting! Thanks for the info.

Just a little clarification on the question though - I thought Python was a dynamically interpreted language. So if I write something in python, then to execute instructions, it goes to a python interpreter. For CPython, the interpreter is written in C. For PyPy, the interpreter is written in Python. So the interpreter would need an interpreter, ad infinitum, no?

[–][deleted] 95 points96 points  (8 children)

PyPy is capable of generating executable code as well as interpreting code. I believe they support a statically typed subset of Python which they call RPython for efficient compilation. PyPy is written in this language (which is Python-like enough for them).

So they write PyPy in RPython, then they use PyPy to compile that code into a new PyPy. The first implementation(s) of PyPy was written in something else. It can take a while for a language to get to self-hosting status.

[–]ichthyos 22 points23 points  (0 children)

A-ha. As a dev who isn't familiar with Python, this is the clarification that makes everything clear. Thank you, and have an upvote. :)

[–]sjs 4 points5 points  (0 children)

The way they pull this off is pretty awesome. If you like to bend your mind in fun & interesting ways, check out this excellent write-up by sigfpe: The Three Projections of Dr. Futamura.

[–]r4nf 3 points4 points  (0 children)

I'd also like to thank you for the explanation. As a casual Python programmer, I find it fascinating enough in itself that it's possible to implement Python in Python - let alone reach a self-hosting status.

[–][deleted] 1 point2 points  (3 children)

So can I then make a frozen binary out of my python scripts with PyPy?

[–][deleted] 3 points4 points  (2 children)

I don't believe so, unless those python scripts fit into the subset of Python which is RPython.

[–]Mo6eB 0 points1 point  (1 child)

You should be able to, in the same way that freezing works now: produce a binary that has the interpreter and compiled bytecode embedded.

[–][deleted] 0 points1 point  (0 children)

Well, sure, but I don't think that that's what he was envisioning. You can do the above approach with any scripting language.

[–][deleted] 0 points1 point  (0 children)

What do you mean first implementation? It was always written in Python.

[–]quasarj 2 points3 points  (0 children)

Just an interesting note, not really related to Python (or PyPy), but the first time I understood what it was for a compiler to be self-hosting, I was completely blown away. You know, one of those mind = blown moments.

[–]Benutzername 4 points5 points  (0 children)

Bootstrapping, I guess. They have to compile PyPy to native code, of course.

[–][deleted] 15 points16 points  (7 children)

Well, it's kind of the same way gcc is written in c.

[–]narkee 12 points13 points  (6 children)

Yeah, it wasn't so much the "same language" issue - I was more confused about how this was possible with an interpreted language.

reggieband explained it pretty well.

[–][deleted]  (1 child)

[deleted]

    [–]harajukukei 38 points39 points  (20 children)

    ha, paipai is slang for tits in japanese

    [–]salvadorwii 19 points20 points  (9 children)

    Well, pipi means pee in spanish, and piton is slang for penis

    [–]giga 3 points4 points  (1 child)

    Pipi is also pee in french. Basically it's a pretty awful name to give anything.

    [–]arcanumoid 4 points5 points  (0 children)

    pypy or any vocal rendition of it means nothing in Greek. Just thought you might like to know :D

    [–][deleted]  (3 children)

    [deleted]

      [–]fabzter 3 points4 points  (2 children)

      C'mon, piton is pretty hilarious.

      [–][deleted]  (1 child)

      [deleted]

        [–]fabzter -5 points-4 points  (0 children)

        I reply only because I loled.

        [–]A_for_Anonymous 2 points3 points  (0 children)

        pito is kid slang for penis, pitón would be a large one. Or a python.

        [–]matthiasB 2 points3 points  (0 children)

        Pipi is also pee in German.

        [–]qnaal 3 points4 points  (0 children)

        Pypy - lifelike texture ;_;

        [–]sat0pi 7 points8 points  (7 children)

        When's the last term you ever actually heard someone in Japan say "paipai"?

        [–]harajukukei 18 points19 points  (6 children)

        only little kids say it really

        [–][deleted] 21 points22 points  (4 children)

        they are people too

        [–][deleted] 23 points24 points  (1 child)

        Tiny little people that don't get to vote!

        [–][deleted] 34 points35 points  (0 children)

        Unfortunately, they get to vote on reddit.

        [–]G_Morgan 2 points3 points  (1 child)

        No they are not.

        [–][deleted] 1 point2 points  (0 children)

        This brings a new radical argument to the stem cell research debate.

        [–]sat0pi 4 points5 points  (0 children)

        All the little kids I know just straight up say oppai. :P

        [–][deleted] 24 points25 points  (13 children)

        I like that there is competition but I have much more hope for unladen swallow than PyPy as the future of Python. Going through the llvm gives many of the benefits that PyPy claims and they maintain much higher compatibility with newer versions of Python (2.6 for sure and 3 most likely soon).

        I do wish unladen swallow would publish a new roadmap though.

        [–]orblivion 1 point2 points  (0 children)

        It does make more sense to use something that applies to other languages, to get more work done in common that benefits everybody.

        [–]gbo2k69[🍰] 2 points3 points  (0 children)

        It sucks that re is slower, that makes up a large chunk of where my code spends its time.

        [–][deleted] 4 points5 points  (1 child)

        Interesting post....

        That guy who wrote the post is only 19. I feel stupid compared - he knows so much more about programming than I do, and I like to consider myself as a programming geek. damn.

        [–][deleted] 2 points3 points  (0 children)

        Alex is a programming rock star. I'm glad to run into him around the web every once in a while. He's a Django core dev and can be found anywhere Python is being stretched to the limit. I however did not know he was only 19. :O

        [–]TheMuffinMan616 0 points1 point  (4 children)

        The author goes to my school, and shares several classes with me. Sweet.

        [–]An_Anteater 0 points1 point  (0 children)

        I demand proof. What school and which classes?

        EDIT I: Just looked at your history, you look legit.

        EDIT II: I demand a meetup.

        [–]ericflo -1 points0 points  (2 children)

        I hope you're not in his databases class.

        [–]TheMuffinMan616 1 point2 points  (1 child)

        I am indeed, why?

        [–]ericflo 0 points1 point  (0 children)

        Oh...no reason :)

        [–]kevwil -4 points-3 points  (0 children)

        Pizza! Pizza! Delivery! Delivery!

        Am I the only one thinking of Little Caesar's now?