Jump to content


Java or C++


39 replies to this topic

#21 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 30 September 2009 - 11:04 PM

Quote

The only difference is that in C++ everything blows up (if you're lucky), while .Net and Java throw an exception.

Yeah, but that's a pretty big difference. In other words, one tells you something is wrong, one lets you believe everything is hunky dory until the lights go out. Those exceptions are errors that have to be fixed before you can resume programming. Leaking memory is generally caused because resources weren't cleaned up. Since it's automatic in c# or java, that's going to happen a lot less. I'm a low quality c++ programmer so I have first hand knowledge in this. It's fine to push it for people wanting to go into the trade, but for amateurs or indies, it really doesn't make sense. There's just too much for one person to do and languages like java or c# are pretty fast so there isn't going to be much of a difference. These arguments are obviously in error or you wouldn't see this explosive growth in programmers for managed languages.
Currently using Blender and Unity.

#22 SyntaxError

    Valued Member

  • Members
  • PipPipPip
  • 139 posts

Posted 30 September 2009 - 11:54 PM

fireside said:

Languages keep moving to simpler models as computers get faster. I can use c++, and I have for a few almost games I've done with it, but I don't particularly like it and I wouldn't use it unless I felt it was necessary, which it really isn't for anything I plan to do anymore.

Well that may be the case for you however I'm pushing the speed limit as it is. I certainly wouldn't call myself a C++ fanboy but I end up being one by default. There is really no other solution for me. Most newer languages (at least the ones with any kind of popularity) seem to take the byte-code/Jit approach. I'm not sure why someone doesn't try to come up with a more modern compiled and optimized language, but so far C++ is it. Coding in something like C# would give my software extremely poor performance and basically make my project untenable. I'm sure that's why many large corporate projects are still written in C++. There is simply no other viable option.

fireside said:

If you want to do it professionally, it's a necessity. If you're a hobbyist or indy, it isn't.


I'm indy and it's very much a necessity for me. In my view the language choice is driven by the problem being solved not a label given the developer.

fireside said:

If you don't think it's harder, you probably haven't used higher languages much.

I've been programming in C++ for a lot of years and have a fairly large personal library at my disposal. There is also the standard library available to everyone. However, I do still consider some newer languages easier to program in but not enough so as to offset the performance penalty, loss of flexibility and loss of industry resources.

#23 Reedbeta

    DevMaster Staff

  • Administrators
  • 5307 posts
  • LocationBellevue, WA

Posted 01 October 2009 - 12:05 AM

SyntaxError said:

I'm not sure why someone doesn't try to come up with a more modern compiled and optimized language, but so far C++ is it.

You may be interested in checking out the D programming language - it's supposed to be a modernized, garbage-collected C++, but still compiles to native code. Last I checked, the compiler was fairly buggy and the language design was in a lot of flux (at least the 2.0 fork), making it tough to use for serious development, but that was a couple years ago and it's likely things have improved since then.
reedbeta.com - developer blog, OpenGL demos, and other projects

#24 SyntaxError

    Valued Member

  • Members
  • PipPipPip
  • 139 posts

Posted 01 October 2009 - 12:21 AM

Reedbeta said:

You may be interested in checking out the D programming language

I have heard about it and maybe at some point this will be the way to go. As it stands it doesn't have enough critical mass to make it worth the effort. But your are correct in that it's something to keep an eye on.

#25 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 01 October 2009 - 01:08 AM

Quote

I'm indy and it's very much a necessity for me. In my view the language choice is driven by the problem being solved not a label given the developer.

That's definitely true, but not the case for most indies and amateurs. One person can only do so much art, so large world games, about the only place that could happen, aren't made that much. Usually it's more symbolic art where the game play is different enough to set it apart or smaller worlds. I would like to see some speed tests done between c# and c++, really. I think there are certain cases with JIT compilers that they can actually be as fast as c++. Also, like you said you had quite a few years of experience in c++. An indy writing a game usually needs to learn artistic software so doesn't generally have those extra years.
Currently using Blender and Unity.

#26 SyntaxError

    Valued Member

  • Members
  • PipPipPip
  • 139 posts

Posted 01 October 2009 - 01:41 AM

fireside said:

I would like to see some speed tests done between c# and c++, really. I think there are certain cases with JIT compilers that they can actually be as fast as c++.

You know I've done it enough times already but I always get arguments even after I post results. Now I make someone else pick the algorithm. The best I ever get is about 2.5X slower for C# and more often I've gotten a lot worse. If I take over memory allocation in C++ (which I almost always do for real projects) C# looks even slower by comparison.

If you want to, write a simple C# program and post it. Make it something that doesn't use I/O so we are testing raw speed. Something simple: bubble sort, some memory allocation test, whatever you like. I'll code it in C++. I'm not saying you are wrong about the C# JIT compiler being as fast as C++ but I have yet to find the case where it is. In addition, the times I have tried to write something real in C# it noticeably drags. Maybe it's my fault. It's just that I've gone through the song and dance so many times now and I've never found C# to be all that fast no matter what some people claims are. It has gotten somewhat better over the years though.

#27 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 01 October 2009 - 02:24 AM

Quote

You know I've done it enough times already but I always get arguments even after I post results. Now I make someone else pick the algorithm. The best I ever get is about 2.5X slower for C# and more often I've gotten a lot worse. If I take over memory allocation in C++ (which I almost always do for real projects) C# looks even slower by comparison.

That would surprise me. However, if you use XNA, which is mainly written in c++, I think you would still find overall game speed to be very close. Off the wall estimates I have heard are 5% slower, but I've never seen a true comparison. It would also depend on type of game, etc. I'm not at all a Microsoft fanboy, but XNA seems like the best and most open platform for indy developers. Once you write a game, you still have to get it out there and that can be very hard. I also have only a little to do with c#. I've written a small game in java and a couple in assorted script languages. It's just what I would probably choose right now if I were to do a 3d game.
Currently using Blender and Unity.

#28 SyntaxError

    Valued Member

  • Members
  • PipPipPip
  • 139 posts

Posted 01 October 2009 - 03:08 AM

fireside said:

That would surprise me. However, if you use XNA, which is mainly written in c++, I think you would still find overall game speed to be very close. Off the wall estimates I have heard are 5% slower, but I've never seen a true comparison. It would also depend on type of game, etc. I'm not at all a Microsoft fanboy, but XNA seems like the best and most open platform for indy developers. Once you write a game, you still have to get it out there and that can be very hard.

I suppose it depends on what is in the game you are developing. I'm not familiar with XNA but I seriously doubt it implements even a fraction of what I personally need. So far I have implemented 2D and 3D Perlin and simplex noise and special versions of the 2D noise that work over the surface of a sphere. I have custom meshes that support LOD and hierarchy for collision detection. I also have taken great pains to handle numerical precision properly because my world is so large. I double buffer my geometry so I can do LOD in the background and still keep the frame rate high. Is XNA going to do any of this for me? Will it even allow me to do this? I'm not saying no one should use XNA but if you are trying to write a leading edge game it may or may not be the best option.

Also if XNA is truly a library written in C++ then I should be able to call it in C++ right? Or does MS insist that you use C# with XNA? Can I port an XNA program to apple? Can I port it to Linux?

In any case if you really want to do a somewhat fair comparison of language speeds, do some simple speed tests. Don't take my word for it, do them yourself. I'll be happy to be proven wrong. I can make a one line call in Lua to a giant piece C++ code. It may be very fast. But that says nothing on how fast Lua is as a general purpose programming language.

#29 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 01 October 2009 - 03:16 AM

It sounds like you are doing something too specific to use a game engine, really. I wish you luck with it. XNA can be accessed with c++ and you can download the framework with visual c++ Xpress, I think. The only reason you might want to look at it is for distribution purposes or otherwise find out what Microsoft requires for that type of thing. I only breezed though a quick explanation of the whole thing, but it sounded like a very useful way to possibly market a game. You have to join some deal or other that costs a hundred dollars a year and you can compile for xbox or pc or even zune and market with their network, though that last wouldn't apply in your case. Linux and Apple, no way.
Currently using Blender and Unity.

#30 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 01 October 2009 - 03:16 AM

Reedbeta said:

You may be interested in checking out the D programming language - it's supposed to be a modernized, garbage-collected C++, but still compiles to native code. Last I checked, the compiler was fairly buggy and the language design was in a lot of flux (at least the 2.0 fork), making it tough to use for serious development, but that was a couple years ago and it's likely things have improved since then.

I've had a quick glance over at D. It looks like they're on the right track, but it seems to me that they're just piling up as many features as possible onto the language. It must have something like double the keywords of C++.

#31 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 01 October 2009 - 10:17 PM

fireside said:

Yeah, but that's a pretty big difference.
No, it's not.

Quote

Those exceptions are errors that have to be fixed before you can resume programming.
You have to trigger them in the first place. Which is just the same as with a non-managed language. The mere difference is in security, but you don't care about security with games. It just needs to run free of errors. And whether you get crashes or runtime exceptions, both are errors, and both you don't want in your game.

Most people think that when programming in a managed environment you can't make errors. This is totally not true.

Quote

Leaking memory is generally caused because resources weren't cleaned up. Since it's automatic in c# or java, that's going to happen a lot less.
No it is not. If you hold a pointer to an object somewhere, the garbage collector is not going to clean up your resources. Object lifetime is *still* something that needs to be considered in a managed environment. And the fact that people know there is a garbage collector cleaning up after them makes them think about object lifetime a whole lot less. People tend to think they can't leak memory in Java or C#. Those people are just wrong ;)

By the way, for the record, I'm not saying that managed languages are not easier. I'm just saying that your arguments are bogus :)
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#32 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 01 October 2009 - 10:41 PM

Quote

By the way, for the record, I'm not saying that managed languages are not easier. I'm just saying that your arguments are bogus

Interesting article. I think though, that managed languages have a lot more safeguards built into the system and they do stop errors that wouldn't be found when using c++. Also, since there isn't any delete for resources in java or c#, obviously this is being done automatically. It might not work once in a while, but mainly it's pretty reliable. I've never seen an out of memory error with java and I've been on java sites and never seen it mentioned. People program these things relatively freely. It doesn't mean you can't make mistakes, but my own personal experience is that there are a lot less with a managed language and you find them sooner. I've programmed in both and I have a lot more crashes in c++ and they're a lot more fatal. Sometimes bringing down the whole OS. Security is also important in games. A lot of it is the language itself. Like having a size property for an array, etc. Those things make better programmers. You can run around it all you want but managed languages are more stable and more secure unless you're an uber c++ programmer.
Currently using Blender and Unity.

#33 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 02 October 2009 - 05:08 AM

I personally have much more memory management issues in C# compared to C++ simply because of the lack of RAII. I have to manually code in the equivalent of C++'s automatic destructor calls because GC finalizing is nondeterministic. IDisposable is not an adequate replacement.

#34 rouncer

    Senior Member

  • Members
  • PipPipPipPip
  • 2722 posts

Posted 02 October 2009 - 06:41 AM

Dont ever be afraid to say something you think is true.
you used to be able to fit a game on a disk, then you used to be able to fit a game on a cd, then you used to be able to fit a game on a dvd, now you can barely fit one on your harddrive.

#35 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 02 October 2009 - 12:07 PM

Quote

I personally have much more memory management issues in C# compared to C++ simply because of the lack of RAII. I have to manually code in the equivalent of C++'s automatic destructor calls because GC finalizing is nondeterministic. IDisposable is not an adequate replacement.

Why would you use it that way? Why not just use c++? It's like saying it's a lot more work because you have to force it into behaving like c++. The only thing I've noticed with java and I read something in a c# comment that there is a forced frame rate with XNA when using c# of 60 fps. That allows a little pause for the GC I think. If you run it at highest frame rate there is a stutter when the GC works. I don't know of any java developers that are doing something like that and I've played quite a few java games. I don't think C#/XNA developers are doing that either. I really can't say because I'm just looking at it now. If I have to do that, I won't bother with it.
Currently using Blender and Unity.

#36 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 02 October 2009 - 02:04 PM

Quote

Why would you use it that way? Why not just use c++? It's like saying it's a lot more work because you have to force it into behaving like c++.

I'm not forcing it behave like C++, I'm forcing it behave in the way I need it to, and I just happens to be the case that C++ can handle that situation whilst C# cannot (easily).

#37 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 02 October 2009 - 02:41 PM

fireside said:

Interesting article. I think though, that managed languages have a lot more safeguards built into the system and they do stop errors that wouldn't be found when using c++.
Only when you're using the raw low-level features of C++. The point is, you don't have to use pointers or native arrays. If you just stick to classes like std::vector and std::tr1::shared_ptr, and never point to interiors of objects (as it is not possible in C# or Java either), it's actually not much different from a managed language. Also, you can use raw pointers and corresponding arithmetic in C# and crash the application as well.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.

#38 fireside

    Senior Member

  • Members
  • PipPipPipPip
  • 1587 posts

Posted 03 October 2009 - 12:40 AM

Quote

Only when you're using the raw low-level features of C++. The point is, you don't have to use pointers or native arrays. If you just stick to classes like std::vector and std::tr1::shared_ptr, and never point to interiors of objects (as it is not possible in C# or Java either), it's actually not much different from a managed language. Also, you can use raw pointers and corresponding arithmetic in C# and crash the application as well.

I somewhat agree with you. One thing I never tried in c++ was shared ptr, which I'll take a look at if c# doesn't quite cut it. Whatever does the job the easiest is what I want. I also don't really like the c++ language as much because I think it has a lot of inconsistencies. It didn't start out as an OO language and it's held onto a lot of old ways. What I care about is getting a game finished. If c# can do what I want I'll use it because it seems better organized to me and more OO. If speed becomes a factor, I'll use c++. I've just barely looked at a 2d game with XNA, but it looks pretty nice. I'll take it one step at a time. Language is just a means to an end as far as I'm concerned.
Currently using Blender and Unity.

#39 poita

    Senior Member

  • Members
  • PipPipPipPip
  • 322 posts

Posted 03 October 2009 - 04:42 AM

I can agree with the language inconsistencies. Despite how much I love the language, C++ is a bit of a kludge. Too many conflicting ideas. D was a good idea, but too much bloat imo.

#40 .oisyn

    DevMaster Staff

  • Moderators
  • 1842 posts

Posted 03 October 2009 - 04:20 PM

fireside said:

Whatever does the job the easiest is what I want.
I totally agree on that one.

Quote

It didn't start out as an OO language and it's held onto a lot of old ways.
Well, it's not trying to be an OO language in the first place. It's a hybrid language, made out of procedural, OO and metaprogramming paradigms, and you can choose whatever fits your needs best. But yes, it's a bit outdated. C++0x will fix a lot of issues (such as a threading library, a better memory model for multithreaded applications, lambda's and closures, etc.). However, I still miss native reflection.
C++ addict
-
Currently working on: the 3D engine for Tomb Raider.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users