Saturday, 13 March 2010

A Comparison of Qt and Java for Large-Scale, Industrial-Strength GUI Development

Here is an interesting paper for you to read:
Just skimmed through it. The good thing is that it is based on research (numbers do not lie ;) ) and not just some anecdotal "evidence". My thoughts? If you are a computer scientist who really knows their stuff and can choose between C++ and Java for your next project - choose C++. If you are an entrepreneur or a manager - hire the best programmers and choose C++... or Python... or Python & C++... and Qt ;)... or use OpenLaszlo... or ZK... or whatever ;)...
BTW, if you are a Java (or C#) programmer interested in mastering C++ & Qt then here is a nice book for you, which, apart from introducing Qt, contains a chapter (well, an appendix really) entitled "Introduction to C++ for Java and C# Programmers":

C++ GUI Programming with Qt 4 (2nd Edition)

The best thing is that the book has been published under the Open Publication License so it can be also legally downloaded from the Internet.

But returning to the paper... if you don't feel like reading the whole then here are some interesting excerpts:

In conclusion: both research and practice contradict the claim that Java programmers achieve a higher programmer-efficiency than C++ programmers.

Both independent academic research and industrial experience demonstrate that the hype favouring Java is mostly unjustified, and that the C++/Qt combination is superior.

Research shows that in practice, garbage collection and other Java features, do not have a major influence on the programmer-efficiency. One of the classic software estimation models, Barry Boehm’s CoCoMo1 predicts the cost and schedule of a software project using cost drivers which take into account variables like the general experience of a programmers, the experience with the programming language in question, the targeted reliability of the program, etc. Boehm writes that the amount of effort per source statement was highly independent of the language level. Other research, for example, A method of programming measurement and estimation by C.E. Walston and C.P. Felix of IBM, points in the same direction.

This is also backed up by our own experience: if programmers can choose their favorite programming language (which is usually the one they have most experience of), programmers with the same level of experience (measured for example, in years of programming experience in general) achieve about the same programmer-efficiency.

Another interesting aspect that we noted (but which is not yet supported by any formal research) is that less experienced developers seem to achieve somewhat better results with Java, medium-experienced developers achieve about the same results with both programming languages, and experienced developers achieve better results with C++.

Again, Prechelt provides useful data. The amount of data he provides is huge, but he arrives at the conclusion that "a Java program must be expected to run at least 1.22 times as long as a C/C++ program". Note that he says at least; the average runtime of Java programs is even longer. Our own experience shows that Java programs tend to run about 2-3 times as long than their equivalent C/C++ programs for the same task. Not surprisingly, Java loses even more ground when the tasks are CPU-bound.

When it comes to programs with a graphical user interface, the increased latency of Java programs is worse than the runtime performance hit. Usability studies show that users do not care about whether a long running task takes, say, two or three minutes, but they do care when a program does not show an immediate reaction to their interaction, for example when they press a button. These studies show that the limit of what a user accepts before they consider a program to be "unresponsive" can be as little as 0.7 seconds.

Prechtelt provides figures which state that on average (...) and with a confidence of 80%, the Java programs consume at least 32 MB (or 297%) more memory than the C/C++ programs (...). In addition to the higher memory requirements, the garbage collection process itself requires processing power which is consequently not available to the actual application functionality, leading to slower overall runtimes.

When dealing with external programs and devices, for example, during I/O or when interacting with a database, it is usually desirable to close the file or database connection as soon as it is no longer required. Using C++’s destructors, this happens as soon as the programmer calls delete. In Java, closing may not occur until the next garbage collecting sweep, which at best may tie up resources unnecessarily, and at worst risks the open resources ending up in an inconsistent state.

The fact that Java programs keep memory blocks around longer than is strictly necessary is especially problematic for embedded devices where memory is often at a premium.

To sum up this discussion, we have found C++ to provide much better runtime- and memory-efficiency than Java, while having comparable programmer-efficiency.

No comments:

Post a Comment

Popular Posts