Which language is better to learn? C++ or Java?

Member
Posts: 749
Joined: 2003.01
Post: #61
Hm that's weird... Using Xcode's "New Project"->"Java"->"Java Tool" , changing the configuration to "Release" and running the code it takes 7772 milliseconds (1238 for C).

Are you using the Gnu Java Compiler to get those numbers?

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Moderator
Posts: 623
Joined: 2007.09
Post: #62
I think the point is that benchmarks can be rigged. Ninja

- Lincoln Green
http://www.binkworks.com/
Luminary
Posts: 5,143
Joined: 2002.04
Post: #63
No, I'm just using the stock Java compiler and Java runtime for Snow Leopard.

Are you using Java 1.4? Wink
Member
Posts: 749
Joined: 2003.01
Post: #64
Hm I have J2SE 5.0 (1.5.0_20) while apparently Snow Leopard has Java SE 6 (1.6)

That's some nice speed bump apparently Smile

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Moderator
Posts: 3,571
Joined: 2003.06
Post: #65
Hmph... I just discovered that Java templates aren't even included in Xcode 3.2.1. Apparently you can either copy them over from older versions of Xcode, or use Eclipse instead. I'm actually a little surprised Apple made this move to start pushing Java out of Xcode. I wonder what the motivation was?
Luminary
Posts: 5,143
Joined: 2002.04
Post: #66
I'd hazard a guess that they don't want people thinking that Java (+Swing) is an acceptable way to make a native Mac application...
Sage
Posts: 1,482
Joined: 2002.09
Post: #67
That and who would use XCode to develop Java applications? It's a mediocre C/C++ IDE. Makes about as mediocre of a Java IDE.

The big problem with Java performance is, yes, it can be very fast, but you have to get much more involved to make it fast. As soon as you stop working primarily with primitive local variables, you are going to see a major performance hit. You can't really use lightweight structs for things like vectors or rotations without incurring a object price tag for them. You also can't use structs to easily build simple data structures you would use in a game like an interleaved array with more than one type of primitive data. I'm not even certain how one would go about doing that in Java.

With vector math in C/C++, you can define inline functions that take and return structs without allocating any new memory on the heap. The compiler is (usually) smart enough to allocate them on the stack and deal nicely with temporary values without copying etc. In Java, if you want to get similar performance you basically have to hand inline all your vector operations so that your temporary values are all primitives within the function call. Say goodbye to readability.

On the other hand, one might think it can't possibly be that bad to make a vector structure and just allocate a new one for every calculation. At least it will be simple and readable... 10x or more performance drop for you! Java may have fast memory allocation/collection, but it's still going to kill your performance when you are creating millions of intermediate values that are only used once when fed into the next function.

I've also seen/tried using mutable operations (thisVector.add(otherVector) modifies thisVector instead of allocating a new one). The performance is a little better, but still pretty horrible and you end up making a disaster of the code. Readability plummets as you assume the role of managing and naming the temporary values needed in the calculations instead of letting the compiler do it and figure out how to best fit those values into registers. When using objects this way I can't imagine that java is smart enough to map object instance variables into registers like C can with structs on the stack.

That is a large part of why I find Java to be a painful language to work with for math/graphics/physics. There are many types of games that I think Java is well suited to making, and many that it's very poorly suited for. I personally want to be making the sort that it's poorly suited to, so I'll probably never use Java outside of work.

edit:
I didn't make my point very clear I suppose. You can make fast programs in Java if you are willing to do more work than equivalent code in C. I prefer a hybrid approach most of the time. Write most of your code in a slower but easier to use language and put the small performance critical parts in a language like C where it's easy to profile and make reasonable optimizations.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Member
Posts: 144
Joined: 2009.11
Post: #68
AnotherJake Wrote:Hmph... I just discovered that Java templates aren't even included in Xcode 3.2.1. Apparently you can either copy them over from older versions of Xcode, or use Eclipse instead. I'm actually a little surprised Apple made this move to start pushing Java out of Xcode. I wonder what the motivation was?

Because both NetBeans and Eclipse are lightyears ahead of Xcode. Both will continuously compile your project in-place, while you're typing. This allows them to highlight bugs - without you hitting compile. They have a really spiffy profiler that works on a truly fantastic range of programs. I've profiled big bad J2EE programs and silly little GUI tools alike.

Xcode, especially considering the additions (by means of integration) with the clang static analyzer, is really making strides to catch up to the level of sophistication present in Java IDEs, but it's not quite there yet.

Java also builds in a very different way than C/C++! C/C++ use a preprocessor, then they compile, then they link. In Java, the linking is done at run-time. The two builders are completely unrelated, and I think it must have been a royal pain to maintain both build systems. If the Java IDEs are better at Java, I say let them have at it. Focus Xcode onto something different and make it excel at it, as opposed to trying to make it into another one of the many failed "multi-language" IDEs.

Everyone's favourite forum lurker!
https://github.com/NSError
Moderator
Posts: 3,571
Joined: 2003.06
Post: #69
OneSadCookie Wrote:I'd hazard a guess that they don't want people thinking that Java (+Swing) is an acceptable way to make a native Mac application...

I forgot they deprecated Java from Cocoa when I was thinking about why they'd remove the Java templates. Can't say I'd blame them for not wanting to contribute to the promotion of Swing being used for "proper" apps on the Mac much.

cmiller Wrote:Because both NetBeans and Eclipse are lightyears ahead of Xcode. ... Focus Xcode onto something different and make it excel at it, as opposed to trying to make it into another one of the many failed "multi-language" IDEs.

That makes sense (including all the other thoughts you added). I haven't programmed in Java in many years so I haven't bothered to try out Eclipse or NetBeans lately, but from your description (and others I've read online) they're really good. I didn't imagine the difference would be that drastic, but I believe, I believe! And you're right that Xcode is struggling to just be good at C/C++ and Obj-C/C++.

BTW, Clang is really rocking for me and that static analyzer has caught some ridiculous but sometimes subtle mistakes I've made.
Sage
Posts: 1,482
Joined: 2002.09
Post: #70
cmiller Wrote:Because both NetBeans and Eclipse are lightyears ahead of Xcode. Both will continuously compile your project in-place, while you're typing. This allows them to highlight bugs - without you hitting compile.

First feature of Eclipse that I turn off... It's not a bug when I haven't finished typing yet! Don't distract me by flickering the line I'm trying to read/write with red highlighting.

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Moderator
Posts: 3,571
Joined: 2003.06
Post: #71
On the topic of languages, but not on Java, has anyone seen Go yet? It appears Google just released it. I was looking through the site and it appears to be really interesting. I'll bet the biggest complaint is going to be lack of operator overloading -- which doesn't matter to me as I'm used to doing things the C way, but I can imagine that one feature alone will scare off most C++ game programmers from even bothering to take it for a spin. Many of the features look quite in-line with what I've wanted to see for a long time.
Member
Posts: 749
Joined: 2003.01
Post: #72
I think programming languages per se are not that exciting... it's what you do with them Wink

©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Moderator
Posts: 3,571
Joined: 2003.06
Post: #73
Najdorf Wrote:I think programming languages per se are not that exciting... it's what you do with them Wink

This guy just did a neat little ray tracer using Go.

I agree with you though that the end results are the important aspect to programming languages.

After fiddling with Go for a few hours, it is certainly interesting, but it's not practically useable right now, as it is in an "experimental" stage. A major issue I see right now in terms of immediate usability is that I can't call out to it from C/C++/etc. It looks to me like Go is to C what D is to C++.

I haven't had enough time to really form much of an opinion on it yet. I'm not sure I'm cool with the lack of manual memory management (for lack of a better term). I wish I could figure out a way to get a graphics subsystem of some sort hooked up to it, like OpenGL. Heck, I'd be okay with software rendering if I could figure out how to do that for now.
Luminary
Posts: 5,143
Joined: 2002.04
Post: #74
http://ooc-lang.org/ is my pick for "most promising upcoming language" at the moment, though I'm far from convinced even by it.
Moderator
Posts: 3,571
Joined: 2003.06
Post: #75
OneSadCookie Wrote:http://ooc-lang.org/ is my pick for "most promising upcoming language" at the moment, though I'm far from convinced even by it.

Interesting. There seem to be some parallels between ooc and Go. I have to agree ooc looks pretty good too. Funny they both include the ":=" thingy for declare/assign (or whatever you call it). I don't get the trend toward mandatory garbage collection (haven't read enough on ooc to know if it forces it, but Go apparently does).
Thread Closed 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Learn java ? icross 6 5,940 Apr 22, 2009 11:11 PM
Last Post: AnotherJake
  What to learn next? stevejohnson 3 3,077 Nov 19, 2006 04:08 PM
Last Post: unknown