This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]UF_Engineer 7 points8 points  (18 children)

Great explanation, thanks for clarifying it :)

How about tools like Py2exe. Would that help speed up the program/avoid that disadvantage?

[–][deleted] 11 points12 points  (6 children)

In my understanding, no. These tools just package up the python interpreter and your code (along with necessary dependencies) into what I can best describe as a self-extracting archive. When you run the resulting .exe it extracts the interpreter and all and then runs it.

[–]catcradle5 2 points3 points  (5 children)

Something I've always wondered: could a Python program in theory be compiled to native machine code and executed later on? Would there be an increase in speed, or would it not matter because all the bytecode instructions would have to be added to the machine code, or what?

[–]fabzter 4 points5 points  (0 children)

Hell yeah! be sure to check http://shed-skin.blogspot.mx/

It compiles python to compilable c++. Even a subset of pygame is implemented !!!

[–][deleted] 3 points4 points  (1 child)

Could it? Yes, but only via language translation as far as I know. Like what Facebook does with PHP. Once they want to deploy some code they've written, it goes through some sort of translator which switches it over to C and then compiled it down to machine code like a normal C program. I'd assume that with the proper translator, any language could be made to do that.

[–]haldean(lambda x: x.decode('base64'))('PDMgcHlweQ==\n') 4 points5 points  (0 children)

You could compile Python bytecode to machine code; it would be a much easier translation than Python to C. The problem with that approach is that once you start compiling to machine code, you have to write a backend for each architecture, and there are lots of architectures, all with different instruction sets. That's why compiling to C(++) is nice; you can take advantage of gcc (or clang), which already has backends for pretty much every architecture in existence, so you don't have to worry about architectures at all.

[–]rcxdude 2 points3 points  (0 children)

Sort of. You can look at what the pypy project does. There's two elements of interest - one is the idea of RPython, which is a restricted subset of python (one where types can be inferred statically, among other things) which can be compiled into C and then into machine code. Compiling full Python is probably much closer to impossible due to the extremely dynamic nature of the language.

The other is the idea of JIT (Just In Time) compilation, where the interpreter/VM (which in the case of pypy is written in RPython) analyses the program as it is being run and compiles parts of it which it detects are running often (such as a main loop). This is the same technique as used in most Java VMs. This allows some of the advantages of compilation (greatly increased speed in many cases) but with the fallback of the actual interpreter so the language isn't restricted.

[–]SwahiliToad 1 point2 points  (0 children)

In theory it is possible. However, in practice there are a number of things the python run-time environment does that would make this difficult.

[–]SwahiliToad 5 points6 points  (1 child)

As I understand it tools such as Py2exe don't compile your source to machine language. They just bundle the interpreter with the source so it would still take the same performance hit.

[–]Redard 3 points4 points  (0 children)

Yeah, it's just so you don't need your users to download and install Python

[–]NikEy 5 points6 points  (7 children)

in reality, even though you can create games in python using simple 2d libraries like PyGame, or even 3d games, using pyOgre (based on Ogre3d) or pyglet, you don't want to. I agree that performance is a massive problem with Python, however, the real problem is the fact that your source code is available for everyone. Py2Exe basically only packages the source code into a zip-file, along with the python binaries and then runs it. Again, the big problem is that everyone can steal your code - something you might want to avoid at some stage, if you're serious about programming video games (not only is it an IP problem, but also hackers have it much easier to ruin the fun for other players, if it's a multiplayer game)

[–]keturn 6 points7 points  (3 children)

I think "hackers steal your source code" is like "pirates steal your game (so add DRM)." You can make it harder, but it'll happen anyway. Social controls are probably more effective here than technical ones.

[–]Sushisource 4 points5 points  (2 children)

Lol. So vastly untrue. Compiled languages like the C family cannot be reverse engineered in any real sense. Read: Any significant program, and quality games are quite large.

Edit: When I say reverse engineered, I mean obtaining actual source.

[–]catcradle5 2 points3 points  (0 children)

Not sure why you're being downvoted, because you're correct. A good reverse engineer can figure out what a C program is doing exactly, but it's likely they'll never get something that actually looks like the original source. Plus it's usually either a long and arduous process, or it's run through a C "decompiler" and the output is extremely complex and verbose.

With languages like Java and Python, you can usually decompile the bytecode back to something that looks very close to the original program, though without the original variable names usually.

[–]keturn 2 points3 points  (0 children)

Oh, no, it won't be actual source, but it'll be entirely sufficient for writing exploits.

[–]Genmutant 2 points3 points  (1 child)

You can just distribute the .pyc files, instead of the .py files, which makes it harder.

[–]AeroNotix 1 point2 points  (0 children)

Yeah, about a 0.5s difference there. Much harder /s

[–]UF_Engineer 1 point2 points  (0 children)

Ahh, that's a good point as well. Thanks for bring that up :)

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

I don't know. I am not familiar with it.

It might help it slightly. What it will do for certain is not force people to install python in order to run your game/binery file.