Pro's & Con's of Python, Java, C++?

Started by
15 comments, last by Rickmeister 18 years, 9 months ago
Python has very good documentation.

Advertisement
Quote:Original post by Rickmeister
Quote:Original post by sykonet
I think Vampire: The Masquerade was done in java (if I recall correctly, it's been awhile.)


Not true.. They used Java as a scripting language, while the core of the game was written in C++ Link

Don't get me wrong here, as I think that Java is the coolest language of them all. The only time I would recommend you to stay clear from Java is when writing a new OS...quite frustrating to do such tasks without pointers :) Java does have some performance issues when compared to languages compiled to native code (binary format), atleast when it boils down to raw computing power - but I feel more comfortable with Java. The only drawback is that I think it's easier to write bad (as in slow) code with Java.


As I said, I wasn't sure, I looked at some of its files a long, long time ago and remember seeing some java stuff in there, so...yeah, I guess I was wrong, well, half way.
Well, since Aldacron has given The Definitive Guide to Java, I shall attempt to do the same thing for Python.

Python is, as has been said, easy to learn, easy to write programs in, and very slow compared to the other two languages. However, depending on what kind of game you want to make, speed may not be as much of an issue (ie for a text-adventure or turn-based strategy game/dungeon crawl), and in that case you will probably save a LOT of time by coding in Python. It is specifically designed to give you shortcuts that aren't avaliable in lower-level languages like C++ and Java.

Anyway, the cons for Python are much the same as Java:
*You must distribute the interpreter (or at least the DLL) with the program, though it's much smaller than Java, and there are programs (py2exe, I think it's called) that will package everything up for you

*Not avaliable for consoles (works just about everywhere else though)

*Programming in Python is easy, optimizing it is a lot harder. A lot of stuff goes on under the hood, and things may not happen the way you think it do; a complete understanding requires a good look at the interpreter internals. This is of course not necessary for just using it, but the learning curve for figuring out how it works may be a bit high.

*It's slow. Very slow, compared to C++. Java is slow too, but Java can be made fast if you know how to do it (most people don't know or don't bother, it seems). In Python, the way to get something done fast! is to re-code it in C.


The pro's:
*It's a wonderful langauge, well-designed, clear, and easy to program in. You can write things FAST in Python.

*There are lots and lots of lovely libraries for it. If you want to do something, there's probably a library for it; anything from graphics to networking to XML parsing to email to data structures...

*There's just as much lovely documentation for it, and the community is both large and helpful.

*Whenever your program fails, it will print a simple, clear exception message, not C/C++'s "Segmentation fault" or Java's 100-line backtrace.

*Dynamically typed... Yes yes, this can be a bad thing too, but not having to declare what types you're using when and how can save a lot of time, and make the program easier to read.

*Garbage-collected. Never get dangling pointers.


Python isn't what you want in every situation, but when you do get the chance to use it, it makes life amazingly easier.
-----http://alopex.liLet's Program: http://youtube.com/user/icefox192
Quote:Original post by Aldacron
I don't know why people list 'no pointer access' as a con. It's really not as big a deal as people think it is. You don't need pointers in Java, so you don't miss them at all.


More accurately:

Java does all the common pointer operations for you behind the scenes when you write something normal looking, and it's easy with practice to refactor unusual pointer operations into more common ones - trust us on this one. As a con, you lose control over the number of levels of indirection (because they get automatically generated for you, and to avoid it you have to fight the language and write in a more procedural style); as a pro (a big pro) you don't have to distinguish * from [], . from ->, worry about pointers vs. references, or in general write extra punctuation that C++ forces on you - plus, you get well-defined behaviour out of a bad pointer (although it still normally indicates a bug you have to fix).

Quote:When you program in Java, think in Java. If you think in C++ while cranking out Java code you'll never be an efficient Java programmer. And for the millionth time - it's not interpreted anymore!.


Very, very true. RAII is largely at odds with the GC approach - both work if you design for them and use the tools you're given the way they're meant to be used.

Quote:My perspective of Java cons, for game programming:

* not currently available on consoles


It *is* available on handheld devices. :)

Quote:* online distribution issues - Do you require the user to download the JRE if it isn't installed already, or do you bundle it with your app? For a budget game this could make or break you. For a packaged CD it's not an issue.


Every common OS installation I can think of these days installs a JRE.

Quote:* lack of third party game dev tools - while there are some fantastic IDEs for Java, game-specific tools are lacking. There's are a handful of open source and commercial 2D/3D game engines being developed (I don't believe any of them complete), and some cross-platform native bindings for OpenGL, OpenAL, and JInput, but that's it. Contrast that with the plethora of C++ game tools available.


This is true. The games industry moves *slowly*. People don't know how to use the C++ standard library (with std::vector et al) properly in games, so they forget about it entirely, and end up basically writing C.

Quote:* bad reputation - most gamers know nothing of the tech used to create games, but I have seen on some gaming message boards that Java isn't as unknown as one would think. The problem is that those gamers who do know about it only have heard that 'Java is too slow for games'. They automatically dismiss any game they hear is made with Java.


Another problem is that by the time people began to come to their senses about this, C# had already started to make waves.

Quote:* easy to learn, difficult to master - programming in Java requires a different mindset. Some things you might have learned through another language just do not apply in Java, and can hurt you rather than help you. For example, you have to learn to program for the GC, something you need not be concerned about in C++. Then there's some things that are Java-specific that you need to learn to handle. For example, many people have the misconception that because there's no pointers in Java you can't have memory leaks - not true.


Right. Another thing is that you have to become comfortable with the idea of aliasing objects most of the time rather than copying them. This can actually lead to more memory-efficient designs, because the effort involved is less - in C++ you either bite the big bullet of managing pointers somehow, or bite the small bullet of the Rule of Three (and sometimes people just blow that off, and then don't understand where the bugs come from :) ). Because of the Java object model (which is quite similar in form to what Python does, btw), it's a lot easier to share things that don't need to change.

And yet another thing is that you have to become comfortable with the idea of object identity vs. object equality.

Quote:* reduced development time compared to C++ (not so much Python ;)) - generally, if you know what you're doing, you can be more productive in Java than in C++. I know C++ programmers who will dispute that, and that's why I qualify it with 'generally'. Java has a robust API that simplifies a lot of things for you, things that in C++ you would have to implement yourself or license a third party library for. And I have found that design implementation comes much more naturally when working for Java (but that's me, and others may disagree).


Agreed. The main thing is that the syntax has been greatly streamlined and simplified, and the language does OO-y things by default that you would have to ask for in C++ (in particular, virtual functions).

Quote:* no pointers - yes, I see this as a pro! There are several common mistakes that can cause hard to find bugs in C and C++ when using pointers. Sometimes you don't even know of it until you release the app inton the wild (buffer overflows anyone?). But it's not a panacea, as you can still have NullPointerExceptions thrown when the user runs the app (which is equivalent to an access violation or segfault), and you can still have memory leaks (via dangling references).


Congratulations, you are sane. :)

Quote:People who religiously defend one language over another generally can be ignored, as their opinions are horribly biased - and unfortunately you will find a lot of that here. I try to keep my opinions balanced, but I do favor Java over C++ so you can surely consider me biased.


ITYM people who religiously "support" or "promote" one language. Around here Java needs all the "defense" it can get ;)

Quote:That's why I don't offer any opinions on C++ here (the cons list would be too long :)).


Wait, when did Lisp enter the discussion? :D

Quote:Original post by sykonet
I think Vampire: The Masquerade was done in java (if I recall correctly, it's been awhile.)

And the recent Battlefield 2 uses python for some stuff, such as stat exporting.

No, actually its running on Valve's Source engine, which is C++ using DirectX 8/9.

To the question at hand though: I use C++, simply because its the language that I know and have been using for the past few years. Would I ever attempt to use Java? Sure, but my school (and any school I'm going to be attending) teaches C++ as the main language. Java has its advantages, and is probably a little bit easier to learn than C++, but its not what the school is teaching (at least, here).

I believe Java has come leaps and bounds in its ability to be used for games, and I don't think it'll be long until you see it used in a lot of off the shelve products, especially when MAC OSX switches to Intel. You'll have as many developers as possible wanting to catch that bandwagon!
-John "bKT" Bellone [homepage] [[email=j.bellone@flipsidesoftware.com]email[/email]]
Original post by Icefox
Quote:*Dynamically typed... Yes yes, this can be a bad thing too, but not having to declare what types you're using when and how can save a lot of time, and make the program easier to read.


Statically typed languages like OCaml feature type inference. It isn't exclusive to dynamically typed languages.


Hope this helps.
Quote:Original post by Zahlman
Quote:Original post by Aldacron
People who religiously defend one language over another generally can be ignored, as their opinions are horribly biased - and unfortunately you will find a lot of that here. I try to keep my opinions balanced, but I do favor Java over C++ so you can surely consider me biased.


ITYM people who religiously "support" or "promote" one language. Around here Java needs all the "defense" it can get ;)


I second you on that!

This topic is closed to new replies.

Advertisement