Which language is better to learn? C++ or Java?
bronxbomber92 Wrote:There is D.
I don't know if D is actually any better (I've seen arguments going both ways), but I was talking about "wide-spread", which D is not

I should mention that I think LLVM might be the key to bringing forward a better bare-metal language.
Sauerbraten was written with the Cube engine, too, which was an engine intentionally designed to be weird.
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Najdorf Wrote:You may like the languages or not, still C & C++ compilers make the fastest executables around, and by far.That is not really true. It should read "native compilers make the fastest executables around, and by far", but C/C++ does not outperform other native compiling languages significantly, if at all.
The "speed doesn't matter nowadays" thing may be true for desktop apps, but for games you often have to push things to the edge to stand out from the crowd, and for embedded games you need all the speed you can get.
Sure python or java may be more elegant, but until they get comparable speeds they're not an option I will consider.
But they do outperform Python, Java and Ruby, easily, and by far. (Java is the fastest of these if it has a decent JIT but it still is slow.)
Java is not slow. At certain tasks certain designs of Java code will be slower than certain designs of C/C++ code, and vice versa. You can google up plenty of benchmarks which "prove" Java is faster, or C/C++ is faster, which only goes to prove that it's not clear-cut by any means.
While it's debatable whether Java is slower than C++ or not, I would say that most Java programs are noticeably slower than C++, due to the fact that many people using the Java language seem to have an incomplete grasp of how to use it efficiently.
*EDIT*
That came out sounding way more like flame bait than I meant it to. I know that there are a lot of good Java programmers out there; I've been lucky enough to work by some of them in the past
*EDIT*
That came out sounding way more like flame bait than I meant it to. I know that there are a lot of good Java programmers out there; I've been lucky enough to work by some of them in the past
Worlds at War (Current Project) - http://www.awkward-games.com/forum/
Fair warning: I'm talking out my arse here 
It's not flamebait as much as it is simply debatable. C/C++ largely rely only upon the proficiency of the programmer and the capabilities of the hardware. Java relies on the efficiency of the runtime environment as well as the proficiency of the programmer, on top of the capabilities of the hardware. Yes, theoretically C/C++ is faster, but in practice, those three things overlap greatly. So, as OSC is pointing out, it's pretty fuzzy to call it one way or another.
I would argue that Java, as it is, is generally "slower" from the viewpoint of it not being generally well-implemented, both in runtime environments (e.g. crappy gui kits and buggy VMs), as well as many programmers making a mess of what could otherwise be well-done. Being as how the "hardcore" programmers out there don't generally gravitate toward Java, and it seems like the "newbie" programmers do, in part from universities "teaching" Java, there is a lot of crappy Java code out there as well. None of this works in Java's favor.
IOW, it's not that Java can't be as fast or even faster than C/C++, just that there's a long track record of suckage that precedes it

It's not flamebait as much as it is simply debatable. C/C++ largely rely only upon the proficiency of the programmer and the capabilities of the hardware. Java relies on the efficiency of the runtime environment as well as the proficiency of the programmer, on top of the capabilities of the hardware. Yes, theoretically C/C++ is faster, but in practice, those three things overlap greatly. So, as OSC is pointing out, it's pretty fuzzy to call it one way or another.
I would argue that Java, as it is, is generally "slower" from the viewpoint of it not being generally well-implemented, both in runtime environments (e.g. crappy gui kits and buggy VMs), as well as many programmers making a mess of what could otherwise be well-done. Being as how the "hardcore" programmers out there don't generally gravitate toward Java, and it seems like the "newbie" programmers do, in part from universities "teaching" Java, there is a lot of crappy Java code out there as well. None of this works in Java's favor.
IOW, it's not that Java can't be as fast or even faster than C/C++, just that there's a long track record of suckage that precedes it
AnotherJake Wrote:I don't know if D is actually any better (I've seen arguments going both ways), but I was talking about "wide-spread", which D is not
I should mention that I think LLVM might be the key to bringing forward a better bare-metal language.
D recently nearly died when someone forked the specification and went of and wrote another compiler. They're already in some major trouble with two competing standard libraries (Tango and Phobos), with two active versions of the original language (D 1.x and D 2.x).
If you want to get something done, and perhaps get paid along the way, don't spend much more than a weekend with D. It's an interesting and fun language, but it's not a full-stack.
I think it is important, especially as a moderator, to either know what you are talking about, research what you plan on talking about before talking about it (research does not include reading programming forums), or don't say anything at all.
I also think it is important, especially as a moderator, to not link to websites in signatures that may hinder the credibility of this website and spread false and misleading information.
I also think it is important, especially as a moderator, to not link to websites in signatures that may hinder the credibility of this website and spread false and misleading information.
longjumper Wrote:I think it is important, especially as a moderator, to either know what you are talking about, research what you plan on talking about before talking about it (research does not include reading programming forums), or don't say anything at all.
I also think it is important, especially as a moderator, to not link to websites in signatures that may hinder the credibility of this website and spread false and misleading information.
Points taken! Although I realize your message isn't directed at anyone in particular, it's a good reminder for all of us mods not to go nuts with the BS. It is actually important for mods to help maintain the "signal" level over the "noise".
Also, I would like to second your point on the sig links. I would encourage all moderators to review links in their signatures and make sure they reflect positively on iDevGames. If in any doubt, it'd be best to leave the links out of your sig.
While we know who everyone is around here, and it's not that big of a deal to us, visitors and web searches turn those links up, and with a moderator label under your name, it does matter to some degree in terms of this site's image.
Look I dont know what voodoo you must make to make java run faster than C++ and how people manage to change numbers to prove any point they want but running the Redneck Testâ„¢
int a=0;
int i,j;
for (j=0;j<10;j++)
{
for (i=0;i<1000000000;i++)
{
a=a+1;
}
}
I get Java running in 20 seconds vs C++ running 5 seconds on my Mac. 4x slower and that's just summing integers, if you just start using a 3d math class I'm afraid it's going to get much worse than that.
int a=0;
int i,j;
for (j=0;j<10;j++)
{
for (i=0;i<1000000000;i++)
{
a=a+1;
}
}
I get Java running in 20 seconds vs C++ running 5 seconds on my Mac. 4x slower and that's just summing integers, if you just start using a 3d math class I'm afraid it's going to get much worse than that.
©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
Najdorf Wrote:Redneck Testâ„¢

Your example helps to illustrate OSC's point. If all we had to do was run a Redneck Testâ„¢ on every language, we'd have only one language left: C.
The point is that there is a *LOT* more which determines the relative efficiency of one language over another than simple number crunching. You have to take design patterns into account as well, not to mention the runtime environment. When taking all factors into account, the results sometimes wind up being subjective in nature and hence the endless flamewars, but they can also reveal some surprising speeds where you might not expect them.[edit] Here, check this out: Language Benchmarks
And don't forget to read this page on that: The Computer Language Benchmarks Game
wyrmmage Wrote:While it's debatable whether Java is slower than C++ or not, I would say that most Java programs are noticeably slower than C++, due to the fact that many people using the Java language seem to have an incomplete grasp of how to use it efficiently.
*EDIT*
That came out sounding way more like flame bait than I meant it to. I know that there are a lot of good Java programmers out there; I've been lucky enough to work by some of them in the past
As a battle-hardened and zestfully seasoned Java programmer I have to affirm this. Java prior to version 1.5 was bona-fide slow. 1.5 sped things up significantly. If you see slow 1.5+ Java, it's probably because the programmer is doing something silly.
Treating strings as mutable types is a big one I see quite often. This isn't the only problem, but it's a salient example. Too often Java programmers will += a string type, which is 100% wrong. A string in Java is an immutable type. Using a StringBuilder is the sign of a good Java programmer (or at least one who has been around the block enough to have used the profiler to figure out that java.lang.String causes problems when it's used like an accumulator).
So, no, Java itself isn't extraordinarily slow. There are, however, Java programmers who create extraordinarily slow code. I think that's a problem no matter what language you use, but it seems highly exacerbated with Java.
Let's give that "redneck" benchmark a go:
redneck.c
OK, so I have a 2.26GHz machine, so at one cycle per add it could be done with ten billion adds in 4.425 seconds. Clearly it's not doing ten billion adds. Hmm. Let's have a look at the assembly:
Oh, look at that, it's optimized the entire benchmark away. It's turned that code into int main() { return 0; }. Clever. Let's see if we can short-circuit that:
Nope!
Nope!
Nope!
yay! OK, now let's try java:
redneck.java:
OMG! Java is 0.309s where C is 32s! Java is 100x faster than C!
Oh wait, Java's clearly optimized away the entire benchmark too. The 0.309s time is comparable only to the 0.003s time of the C benchmark. Java is 100x slower to start up than C. Well, that's going to be a critical part of the performance of your game.
Compilers for both languages are smarter than the Redneck benchmark, though.
redneck.c
Code:
int main() {
int a=0;
int i,j;
for (j=0;j<10;j++)
{
for (i=0;i<1000000000;i++)
{
a=a+1;
}
}
return 0;
}Code:
/Developer/usr/bin/llvm-gcc-4.2 -O4 redneck.c
OneSadMBP13:Desktop keith$ time ./a.out
real 0m0.010s
user 0m0.000s
sys 0m0.002s
OneSadMBP13:Desktop keith$ time ./a.out
real 0m0.003s
user 0m0.000s
sys 0m0.002sOK, so I have a 2.26GHz machine, so at one cycle per add it could be done with ten billion adds in 4.425 seconds. Clearly it's not doing ten billion adds. Hmm. Let's have a look at the assembly:
Code:
otool -toV a.out
a.out:
(__TEXT,__text) section
[...]
_main:
0000000100000f80 xorl %eax,%eax
0000000100000f82 retOh, look at that, it's optimized the entire benchmark away. It's turned that code into int main() { return 0; }. Clever. Let's see if we can short-circuit that:
Code:
OneSadMBP13:Desktop keith$ /Developer/usr/bin/gcc-4.2 -O3 redneck.c
OneSadMBP13:Desktop keith$ time ./a.out
real 0m0.011s
user 0m0.000s
sys 0m0.002sCode:
OneSadMBP13:Desktop keith$ /Developer/usr/bin/gcc-4.2 -O2 redneck.c
OneSadMBP13:Desktop keith$ time ./a.out
real 0m0.004s
user 0m0.000s
sys 0m0.002sCode:
OneSadMBP13:Desktop keith$ /Developer/usr/bin/gcc-4.2 -O redneck.c
OneSadMBP13:Desktop keith$ time ./a.out
real 0m0.004s
user 0m0.000s
sys 0m0.002sCode:
OneSadMBP13:Desktop keith$ /Developer/usr/bin/gcc-4.2 -O0 redneck.c
OneSadMBP13:Desktop keith$ time ./a.out
real 0m32.561s
user 0m32.453s
sys 0m0.042syay! OK, now let's try java:
redneck.java:
Code:
public class redneck {
public static void main(String[] args) {
int a=0;
int i,j;
for (j=0;j<10;j++)
{
for (i=0;i<1000000000;i++)
{
a=a+1;
}
}
}
}Code:
javac redneck.java
OneSadMBP13:Desktop keith$ time java redneck
real 0m0.378s
user 0m0.279s
sys 0m0.061s
OneSadMBP13:Desktop keith$ time java redneck
real 0m0.309s
user 0m0.274s
sys 0m0.055sOMG! Java is 0.309s where C is 32s! Java is 100x faster than C!
Oh wait, Java's clearly optimized away the entire benchmark too. The 0.309s time is comparable only to the 0.003s time of the C benchmark. Java is 100x slower to start up than C. Well, that's going to be a critical part of the performance of your game.
Compilers for both languages are smarter than the Redneck benchmark, though.
Hmm, that's weird, on OSX 10.5 , Xcode 3.1.2 and GCC 4.0, "Command Line Utility"->"C++ Tool" template, Release Build, Os optimization, it's running it all even if I didn't ask him to print a (java too...).
Whatever, you can use all the tricks you want to prove me wrong, but if you have him print a (ok, it overflows in this example, make a a float), you'll see it runs 4 times slower, and it's not for the startup time.
Whatever, you can use all the tricks you want to prove me wrong, but if you have him print a (ok, it overflows in this example, make a a float), you'll see it runs 4 times slower, and it's not for the startup time.
©h€ck øut µy stuƒƒ åt ragdollsoft.com
New game in development Rubber Ninjas - Mac Games Downloads
OK, Let's devise a benchmark that the compilers can't fold. Say, the fibonacci sequence. Let's include timing in the code so we don't measure startup time either:
redneck.c:
And it takes about a second to run:
Now Java's turn:
redneck.java:
And it takes a little longer to run:
That's a little less than 1.3x slower. Certainly nowhere near 4x. Not something I'd be worrying about for a game, even.
redneck.c:
Code:
#include <stdio.h>
#include <sys/time.h>
int main()
{
struct timeval t;
gettimeofday(&t, NULL);
long start = t.tv_sec * 1000 + t.tv_usec / 1000;
long i, l = 1, m = 1;
for (i = 0; i < 1000000000; ++i)
{
long temp = l;
l = m;
m = temp + m;
}
gettimeofday(&t, NULL);
long end = t.tv_sec * 1000 + t.tv_usec / 1000;
long duration = end - start;
printf("Result: %ld\n", m);
printf("Duration: %ld\n", duration);
return 0;
}And it takes about a second to run:
Code:
keith$ /Developer/usr/bin/llvm-gcc-4.2 -O4 redneck.c
keith$ ./a.out
Result: 1601461754847896408
Duration: 1087
Redneck keith$ ./a.out
Result: 1601461754847896408
Duration: 1086Now Java's turn:
redneck.java:
Code:
public class redneck
{
public static void main(String[] args)
{
long start = System.currentTimeMillis();
long i, l = 1, m = 1;
for (i = 0; i < 1000000000; ++i)
{
long temp = l;
l = m;
m = temp + m;
}
long duration = System.currentTimeMillis() - start;
System.out.println("Result: " + m);
System.out.println("Duration: " + duration);
}
}And it takes a little longer to run:
Code:
keith$ javac redneck.java
keith$ java redneck
Result: 1601461754847896408
Duration: 1412
keith$ java redneck
Result: 1601461754847896408
Duration: 1410That's a little less than 1.3x slower. Certainly nowhere near 4x. Not something I'd be worrying about for a game, even.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Learn java ? | icross | 6 | 5,202 |
Apr 22, 2009 11:11 PM Last Post: AnotherJake |
|
| What to learn next? | stevejohnson | 3 | 2,455 |
Nov 19, 2006 04:08 PM Last Post: unknown |
|
