views:

1267

answers:

13

I'm thinking of trying to make some simple 2d games, but I've yet to choose a language. A lot of people recommend either C++ with SDL or python with pygame. I keep hearing that developement on C++ is fairly slow, and developement time with Python is fairly fast.

Anyways, could anyone elaborate on this? What exactly makes development in C++ so time consuming? The programs I've made have been Project Euler-style in that they're very short and math-based, so I have no experience in larger projects.

+1  A: 

It's time consuming because in C++ you have to deal with more low-level tasks. In Python you are free to focus on the development of the actual game instead of dealing with memory management etc.

Silfverstrom
+1  A: 

there are many things that make c++ longer to develop in. Its lower level, has pointers, different libraries for different systems, the type system, and there are others I am sure I am missing.

arinte
You can skip most of the lower-level stuff and raw pointers. Memory management has become much easier. You can stick to one system, or use cross-platform libraries. Of course, you can't evade the type system, and as a whole C++ is clumsier than Python. However, it isn't as bad as some people think.
David Thornley
+8  A: 

I've heard these complaints before about C++, but the fact is, programming in any language with which you are unfamiliar is time consuming.

I good C++ programmer can probably crank out the app much faster than an okay Python programmer and visa versa.

I think C++ often gets a bad rep because it allows you get much lower level - pointers, memory management, etc, and if you aren't used to thinking about such things, it can take a bit of time. If you are used to working in that environment, it can become second nature.

Unless choice of language is something imposed upon you by your company, team, client, etc. I usually recommend that folks go with the language they are most comfortable with OR most interested in learning more about. If speed is the issue you are concerned with, look at the learning curve for each language and your past experience. C++ tends to have a higher learning curve, but that too depends on the person.

Kindof a non-answer I know.

James Conigliaro
The biggest productivity gain for C# or Java and many scripting languages, beyond the lack of memory management, is the standard class libraries. The languages themselves aren't that different, the capabilities of the standard libraries though are night and day. From a former C++ programmer, I would bet I average 2 - 3 x more productivity in most applications when working in C#. Of course, YMMV. Also, when you do apples to apples comparisons ( good C++ programmer and a good Python programmer ) in most cases the Python developer will trounce the C++ programmer in speed of completion.
Serapth
Initial point about language familiarity is valid, but there are fundamental language differences that directly affect developer productivity, which you don't acknowledge or address.
John Pirie
@Serapth: I'm not convinced by these arguments though I hear them a lot, I work in a C++ company and we have lots of (non-standard) libraries to speed production. If you want apple for apple comparisons compare a Python developer with a C++ developer with a decent set of libraries. I expect the quicker will be the one whose libraries most closely match the problem. Our libraries fit very nicely into our area so MMDV (my mileage does vary).
Patrick
PS : I would advise a programmer without much knowledge of C++ to go for Python, c# or equivalent, C++ has a steeper learning curve.
Patrick
+19  A: 

There are two things that are relevant between C++ and Python that will affect your time-to-develop any project including a game. There are the languages themselves and the libraries. I've played with the SDL to some extent and peeked at PyGame and for your specific instance I don't think the libraries are going to be much of a factor. So I'll focus on the languages themselves.

Python is a dynamically-typed, garbage-collected language. C++ is a statically-typed, non-garbage-collected language. What this means is that in C++ a lot of your development time will be spent managing memory and dealing with your type structure. This affords you a lot of power, but the question is do you really need it?

If you're looking to write a simple game with some basic graphics and some good gameplay, then I don't think you truly need all the power that C++ will give you. If you're looking to write something that will push the envelope, be the next A-list game, be the next MMO, fit on a console or a handheld device, then you will likely need the power that C++ affords.

Lee
Plus I've heard most console games today are developed with a C++ (very efficient) engine, but the meat of the game (characters, events, etc) is scripted, is this true?
Camilo Martin
I can't speak to "most games", but for desktop games, it is my understanding that what you say is correct. For console games, I would suspect that it is not the case. Even on today's monster consoles, the overhead of an interpreted language (such as Python or Lua) is a luxury that is too expensive to afford for your A-list games.Now, if you mean that these items, characters, etc. are built within tools at a higher level than raw code that then get compiled into some sort of binary object model ... then yes, that would be the case.
Lee
A: 

I'd focus more on choosing a framework to build your game on than trying to pick a language. Unless the goal is to learn how games work inside and out, you're going to want to use a framework. Try out a couple, and pick the one that meets your requirements and feels nice to you.

Once you've picked the framework, the language choice becomes easy - use the language for which the framework is written.

There are many options for game frameworks in C++ - pygame works for python. There are many that work with other languages/tools as well (including .NET, Lua, etc.)

Reed Copsey
+1  A: 

Short Answer

Yes python is faster in terms of development time. There are many case studies in real life that show this. However, you don't want to do a 3d graphics engine in Python.

Unknown
Which shouldn't be taken to mean efficient 3D isn't possible with Python. I don't think anyone would write a 3D engine in Python, but there are several binding over C/C++ libraries... such as PyOpenGL.
Daniel
+14  A: 

The power of Python is in it's ability to allow you to focus more on the problem than having to deal with testing low-level issues such as memory allocation. I can't count how many times days of development have been wasted tracking down memory leaks in C or C++. An advantage of all high level languages.

Python is very easy to learn compared to C++,so you can be up to speed a lot quicker in doing basic programming tasks. Therefore, you'll move quicker into advanced tasks as well.

C++ has a lot of power but has many ways to shoot yourself in the foot compared to Python(not saying that can't be done in Python).

The compile/debug cycle can get old sometimes in C++ depending on what you're trying to do. Although technically speaking, everytime you run a Python script it's getting "compiled" per se, it's just a quicker cycle. A good IDE can help alleviate this is in Python by automatically checking your code for syntax errors while you type it out.

If you have some code you want to test inside a larger project, it's a hassle sometimes to isolate it for testing. Whereas a good Python interpreter such as IPython, makes it easy to test a small bit of code and see how the language behaves and paste it into a file.

Python also interfaces very well with existing C/C++ code through many numerous ways. That way if a new whizbang Python module you created is really slow, then you can soup it up in C/C++ then wrap it up with Python through ctypes, Boost::Python, or SWIG.

And most of all, Python comes with a great standard library that has a lot of stuff figured out for you. It's just a matter of putting the pieces altogether! It has a great community behind it, so if it's not in the standard library, there's a good chance someone out there has solved the problem (PyGame, Numpy, SciPy, Pyserial, PyWin, etc.) for you. You can just google it, grab it and plop the code right into your program...away you go!

DoxaLogos
Bear in mind that memory management in modern C++ is frequently a matter of using smart pointers.
David Thornley
True, that does make it easier, but we have come across problems even with smart pointers.
DoxaLogos
I've had problems with garbage collection, too, although I don't know how good Python's is right now. It's hard to get right. Still, it will only improve from here, and there is some movement in C++ towards GC (although nothing much this standard revision).
David Thornley
A: 

Do you have any programming experience at all? If not, I would start with Python which is easier to learn, even if it is not a better tool for game development. If you decide you want to program games for living, you'll probably need to switch to C++ at some point.

Nemanja Trifunovic
A: 

Note that SDL is currently slow, because it basically doesn't use hardware acceleration. SFML is an alternative of choice, and is available in Python too.

Bastien Léonard
Daniel
+2  A: 

If your main programming experience comes from short, math-based puzzle problems, then it will probably be much quicker for you to learn Python than C++. Python's garbage collection is a big win if you haven't written large programs before. Managing memory yourself is easy to get wrong and can be really hard to debug. On a more subjective note, a lot people find Python more readable.

That being said, static typing might be helpful if you're just making the move to larger programs. The compiler will catch some things that will only show up at run time with Python. And the freedom that Python's dynamic typing allows isn't always a boon if you're new to larger programs. While that freedom can be a good thing for someone who has had some design experience, being forced to obey the constraints imposed by static typing might prevent you from making some bad choices if you're still learning.

For those reasons, I wouldn't rule out Java. It's statically typed and it's garbage collected. It's also a simpler language than C++, but it has a similar syntax. So if you want to work on future projects where performance is more important, you'll be in a good position to make the transition to C++. I'm not sure what the options are for Java game development libraries, but I know I've lost many hours to some pretty addicting Java games, so they must be out there. I don't know if Java will allow you to get as close to the metal as Pygame or SDL will, but in the beginning you probably won't be pushing the performance envelope anyway. Making a complete game is a fair amount of work (more than most aspiring game developers anticipate), and if your first project won't fit within the performance constraints of Java then you might want to consider scaling it back anyway.

MJ
+1  A: 

Python has some big advantages over programming languages like C++. I myself have programmed a lot with C++, C and other programming languages. Lately I am also programming in Python and I got to like it very much!

You can have a quick start with Python. Since it is rather simple to learn (at least with some programming experience and enough abstract thinking), you can have fast successes. Also the script-like behaviour makes starting easy and it is also possible, to quickly test some things in the integrated shell. This can also be good for debugging.

The whole language is packed with powerful features and it has a good and rather complete set of libraries.

There was the argument that with the "right library" you can develop as quickly with C++ as with Python. This might (partly) be, but I myself have never experienced it, because such libraries are rare. I had also a big library at hand, but still lacked many valuable features in C++. The so called "standard template library" STL makes things even worse in my opinion. It is a really powerful library. But it is also that complex, that it adds the complexity of an additional programming language to C++. I really disliked it and in a company I worked in, much worktime was lost, because the compiler was not able to give useful error-output in case of errors in the STL.

Python is different. Instead of putting the "speed of the programm" on the throne -- sacrificing all else (as C++ and especially the STL does) -- it puts "speed of development" first. The language gives you a powerful toolkit and it is accompanied by a huge library. When you need speed, you can also implement time critical things in C or C++ and call it from Python.

There is also at least one big online Game implemented in Python.

Juergen
A: 

It takes about the same amount of time to write the same code in pretty much all of the high level languages. The win is that in certain languages it is easier to use other peoples code. In a lot of Python/Ruby/Perl apps, you write 10% of the code and import libraries to do the other 90%. That is harder in C/C++ since the libraries have different interfaces and other incompatibilities.

C++ vs Python is a pretty personal choice. Personally I feel I lose more time with not having the C/Java class system (more run time errors/debugging time, don't have anywhere near as good auto completion, need to do more documentation and optimization) than I gain (not having to write interfaces/stub function and being able to worry less about memory managment). Other people feel the exact opposite.

In the end it probably depends on the type of game. If your processor intensive go to C++ (maybe with a scripting language if it makes sense). Otherwise use whatever language you prefer

hacken
A: 

Why limit yourself to those two options? With C# or Java you get access to a huge collection of useful libraries plus garbage collection and (in the case of C#) JIT compiling.

Furthermore, you're saying that you're looking to do game development, but from your task description it sounds like you're also looking at coding your own engine. Is that part of the exercise? Otherwise you should definitely take a look at the available Indie engines out there - lots are cheap of not free and open source.

Needless to say, working from an existing engine is definitely faster than going from scratch :)

AngryAnt