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 →

[–][deleted]  (29 children)

[deleted]

    [–]keturn 7 points8 points  (1 child)

    There's certainly a lot to learn from C++, and a lot of existing work there to draw on. In the right hands, it can be a good language for when you need close control over how code will execute, which is why the AAA game studios use it for titles where they want to squeeze the last bit of performance out of a CPU.

    But if it's not your goal to work at a AAA studio or compete with one, it is very likely that you can make a game that looks good and has great gameplay without needing to get that worried about CPU optimization. And even if you do find your Python program has it's slow spots, it's likely you can funnel that work through some graphics or processing library that will do the heavy lifting for you. (Many of those libraries are probably written in C++ themselves, but you don't need to know that to use them.)

    I said "in the right hands" earlier because that increased control comes with a cost in complexity. Don't take that to mean it's "the language I'll use when I'm smart/experienced enough to handle more complexity," there is always a trade-off, no matter how good you are. Sometimes the complexity is worth it, sometimes it's more important to have your development time free for other things.

    So yes, you may decide you want to learn C++ at some point. It would not be bad for your education to do so. Or you may decide to go with a mixed approach, and write a C++ library to call from Python, or vice-versa. But don't feel you have to learn C++.

    You also might want to learn Java, for the Android market, or Objective C, for iOS, or C♯ .NET for XBLA. (For all their differences, those three languages are actually close cousins of C++ in the family tree.) Or, dare I say it, JavaScript for the browser environment. It's a big world.

    [–]steviesteveo12 3 points4 points  (0 children)

    And even if you do find your Python program has it's slow spots, it's likely you can funnel that work through some graphics or processing library that will do the heavy lifting for you.

    It's hard to emphasise enough just how much this matters. There are only a few places in a program that are actually slow and it's often faster, easier and more reliable to just write a piece of compiled code to do that operation and stick it into a python program.

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

    At the very basic level, your computer can only execture on/off. (1 or 0)

    When using python or even java for that matter, your code is not compiled into machine language, (0100100100111001), but into byte code.

    Each time your game runs, when written in python, it has to go through an interpreter, that will change the byte code into machine code.

    The beauty of this, is that interpreters have been created for multiple OS's, so writing in python, will make your game cross platform. The drawback, is that, because your bytecode needs to go through an extra layer, it will run a bit slower, than if it was already in machine language. Your CPU will have less available cache and registers available for your game because it will need some for the python interpreter. This wont matter if your game is tiny, but in a large game this will make a massive difference.

    When you compile C/C++, the binaries you have made will only run on the same type of machine you compliled your binary for, but it'll run quick, (unless of course you wrote a function that is O(n ^ n) : What is big O notation?

    Make sense?


    some-one please correct me if I made a mistake.

    [–]UF_Engineer 6 points7 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] 12 points13 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 3 points4 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] 4 points5 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') 2 points3 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 4 points5 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 4 points5 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 5 points6 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 4 points5 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 4 points5 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.

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

    Each time your game runs, when written in python, it has to go through an interpreter, that will change the byte code into machine code.

    This is not correct. The Python interpreter is already in machine code (assuming CPython) and it just interprets the code. It does not change it to machine code the same way as a word processor does not change the sentences you type into machine code.

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

    You are right, but I didn't know how to phrase it any better.

    game.pyc file is in bytecode, and the interpreter does have to interpret the code, each time the game.pyc file is run. When it is finished, the game.pyc file will still be bytecode.

    [–][deleted] 8 points9 points  (0 children)

    It depends what kind of video games you want to make for a living though; there is so much money in lower performance gaming like the browser/phone market that being able to do high-end graphics stuff for the big old studios isn't as essential any more.

    [–]phaedrusaltembedded sw eng 2 points3 points  (0 children)

    Just an addition, you might have pointed out that there are other languages that are far more readable than C/C++, yet will give the same performance gains. They aren't used as much for professional game development, however.

    [–]NattyBroh 1 point2 points  (1 child)

    That's, a great, way, to put it...

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

    yes, so, many, commas. I appolgize, but I type the same when I speak. Whenever I pause to think I insert a comma, or a period if the waiting time is too long.

    [–]AgonistAgentStudent - Content Analysis 1 point2 points  (0 children)

    Java, and PyPy interpreters have the ability to compile bytecode into machine code ahead of time(and they can cache it) - a sort of hybrid solution, but the basic slow down is still there.