Sunday, January 20, 2019
Java-Whitepaper Essay
This white paper comp ars C++/Qt with chocolate/AWT/ miss for developing king-size-scale, real-world softw ar system with graphical affairr interfaces. References be made to free lance reports that examine unhomogeneous aspects of the two toolsets. 1 A proportion of Qt and chocolate 1. What Do We equalise? When selecting an environment for a large softw be development project, t here(predicate) are m whatsoever aspects that must be considered.The planing run-in is maven of the intimately signifi contrisolelyet aspects, since its choice has considercapable impact on what separate options are on hand(predicate). For example, in a graphical user interface development project, developers will need a graphical user interface library that provides ready-made user interface components, for example, hardlytons and menus. Since the selection of the graphical user interface library itself has a large impact on the development of a project, it is non uncommon for the GUI li brary to be chosen first, with the course of study terminology universe immovable by the languages for which the library is obtainable.Usu aloney, in that location is still one language per library. Other software components like database portal libraries or communication libraries must also be interpreted into consideration, but they seldom rich person such a strong impact on the boilers suit creation as the GUI libraries. In this white paper, the objective is to liken the C++/Qt environment with the coffee/AWT/ tangle environment. In severalise to do this in the approximately useful way, we will begin by tail endvas the programming languages involved, i. e.C++ and umber, and then compare the two GUI libraries, Qt for C++ and AWT/ drop off for coffee. 2. Comparing C++ and umber When discussing the unhomogeneous benefits and drawbacks of particular programming languages, the consider very much degenerates into arguments that are based on personal pay back a nd tasting rather than any objective criteria. Personal preferences and experience should be taken into compute when selecting a programming language for a project, but because it is subjective, it back endnot be considered here.Instead we will cipher at issues such as computer programmer- capability, runtime-efficiency and reposition-efficiency since these dismiss be quantified and turn oer been examined in scientifically conducted research, although we will also hold knowledge based on the practical exerience of projects that have been applianceed in our possess company. 2. 1. Programmer-efficiency Programmer-efficiency describes how efficiently (i. e. how quickly and accurately) a programmer with a presumptuousness degree of experience and knowledge can implement a accredited set of requirements in a particular programming language, including debugging and project frame-up time.Since developer salaries are one of the primary cost concomitantors for any programming project, programmer-efficiency greatly affects the 2 A Comparison of Qt and java cost-efficiency of the project. To some extent, programmer-efficiency is also determined by the tools functional. The main design goal of coffee bean is increased programmer-efficiency compared to different general-purpose programming languages, rather than increased memory- or runtime-efficiency. coffee bean has several(prenominal) features designed to make it more programmer-efficient.For example, unlike C++ (or C), the programmer does not have to explicitly free (give back) allocated memory resources to the operating system. Freeing novel memory (drivel accrual) is bagd mechanically by the java runtime system, at the expense of memory- and runtime-efficiency (see below). This liberates the programmer from the burden of keeping track of allocated memory, a tedious labor movement that is a major cause of bugs. This feature alone should significantly increase the programmer-efficiency of cof fee berry programmers, compared to C++ (or C) programmers.Research institutes that in practice, garbage collection and new(prenominal) coffee features, do not have a major influence on the programmer-efficiency. One of the classic software estimation models, Barry Boehms CoCoMo1 predicts the cost and register 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 aggregate of effort per source arguing 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 IBM2, points in the very(prenominal)(prenominal) direction. Both the reports cited here pre-date the advent of coffee berry by many years, although they seem to reveal a general principle that the sophistication of a general-purpo se programming language has, compared with other aspects, like the experience of the developers, no significant influence on the overall project costs. There is more recent research that explicitly includes umber and which supports this hypothesis.In An empirical comparison of C, C++, Java, Perl, Python, Rexx, and Tcl3, Lutz Prechelt of the University of Karlsruhe, describes an experiment he conducted in which computer science students were assigned a particular design and development task and asked to implement the specification provided in any of the languages C, C++, or Java which they could freely choose according to their personal preferences (the other languages were examined in a different part of the research project). The data collected shows almost the same results for C++ and Java (with C running tercet in most aspects).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 ex perience of), programmers with the same level of experience (measured for example, in years of programming experience in general) achieve close the same programmer-efficiency. Another interesting aspect that we noted (but which is not barely supported by any formal 3 A Comparison of Qt and Java research) is that less see developers seem to achieve somewhat break up results with Java, medium-experienced developers achieve closely the same results with both programming languages, nd experienced developers achieve better results with C++. These findings could be due to better tools being available for C++ nevertheless this is an aspect that must be taken into account. An interesting way to quantify programmer-efficiency is the Function Point method real by Capers Jones. Function points are a software metric that still depend on the functionality, not on the implementation. Working from the function points, it is practicable to compute the lines of code needed per function poin t as salutary as the language level which describes how many function points can be implemented in a certain amount of time.Intriguingly, both the determine for the lines of code per function point and the language level are selfsame(a) for C++ and Java (6 for the language level, compared with Cs 3. 5 and Tcls 5, and 53 for the lines of code per function point, compared with Cs 91 and Tcls 64). In conclusion both research and practice nullify the accept that Java programmers achieve a higher programmer-efficiency than C++ programmers. 2. 2. Runtime-efficiency We have seen that Javas programmer-efficiency appears to be illusory. We will now examine its runtime efficiency. Again, Prechelt provides useful data.The amount of data he provides is bulky, but he arrives at the conclusion that a Java program must be expected to run at to the lowest degree 1. 22 times as long as a C/C++ program. Note that he says at to the lowest degree the average runtime of Java programs is veritab le(a) long-term. Our own experience shows that Java programs slant to run about 2-3 times as long than their equivalent C/C++ programs for the same task. Not surprisingly, Java loses even more show 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 cognitive process hit.Usability studies show that users do not care about whether a long running task takes, say, two or threesome 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 curtail of what a user accepts before they consider a program to be unresponsive can be as little as 0. 7 seconds. Well return to this issue when we compare graphical user interfaces in Java and C++ programs. An explanation about wherefore Java programs are drawn-out than C++ is in order.C++ programs are lay ind by the C++ hoard program into a binary format that can be executed like a shot by the CPU the whole program execution and so takes slur in 4 A Comparison of Qt and Java hardware. (This is an oversimplification since most modern CPUs execute microcode, but this does not affect the issues discussed here. ) On the other hand, the Java compiler compiles the source code into bytecode which is not executed at present by the CPU, but rather by another piece of software, the Java Virtual Machine (JVM). The JVM in turn, runs on the CPU.The execution of the bytecode of a Java program does not take place in (fast) hardware, but sort of in (much gradual) software emulation. Work has been undertaken to develop Just in sequence (JIT) compilers to address Javas runtime efficiency problem, but no oecumenical solution has yet emerged. It is the semi-interpreted nature of Java programs that makes the compile once, run anyplace cash advance of Java achievable in the first place. Once a Java program is compiled into bytecode, it can be executed on any platform which has a JVM.In practice, this is not always the case, because of implementation differences in different JVMs, and because of the necessity to sometimes use native, non-Java code, usually pen in C or C++, together with Java programs. further is the use of platform-independent bytecode the right approach for crossplatform exercises? With a sincere cross-platform toolkit like Qt and good compilers on the various platforms, programmers can achieve almost the same by compiling their source code once for each platform write once, compile everywhere.It can be argued that for this to work, developers need access to all the platforms they motivation to support, while with Java, in theory at least, developers entirely need access to one platform running the Java development tools and a JVM. In practice, no responsible software manufacturer will ever allow their software for a platform the software hasnt been tested on, so they would sti ll need access to all the relevant platforms. The question arises why it should be obligatory to run the Java Virtual Machine in software if a program can be implemented in software, it should also be possible to have hardware implement the same unctionality. This is what the Java designers had in mind when they developed the language they assumed that the performance penalty would disappear as soon as Java CPUs that implement the JVM in hardware would become available. But after five years, such Java CPUs have not become generally available. Java automatically de-allocates (frees) unused memory. The programmer allocates memory, and the JVM keeps track of all the allocated memory blocks and the references to them. As soon as a memory block is no longer referenced, it can be reclaimed. This is done in a process called garbage collection in which the JVM periodically checks all the allocated memory blocks, and removes any which are no longer referred to. Garbage collection is very c onvenient, but the trade offs are greater memory consumption and easilyer runtime speed.. With C++, the programmer can (and should) delete blocks of memory as soon as they are no longer required.With Java, blocks are not deleted until the next garbage collection run, and this depends on the implementation on the JVM being used. 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 appendix to the higher memory requirements, the garbage collection process itself requires processing spot which is consequently not available to the actual natural covering functionality, lead to slower overall runtimes.Since the garbage collector runs periodically, it can occasionally lead to Java programs freezing for a few seconds. The best JVM implementations keep the occurrence of such freezes to a minimum, but the freezes have not been eliminated entirely. When dealin g with external programs and devices, for example, during I/O or when interacting with a database, it is usually desirable to close the file away 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. It is no coincidence that there is (at the time of writing) no complete implementation of the Java platform for embedded devices, only partial implementations that implement a subset.The main reason why garbage collection is more big-ticket(prenominal) than explicit memory management by the programmer is that with the Java scheme, information i s lost. In a C++ program, the programmer knows both where their memory blocks are (by storing pointers to them) and knows when they are not needed any longer. In a Java 6 A Comparison of Qt and Java program, the latter information is not available to the JVM (even though it is known to the programmer), and thus the JVM has to manually find unreferenced blocks.A Java programmer can make use of their knowledge of when a memory block is not needed any longer by deleting all references that are still around and triggering garbage collection manually, but this requires as much effort on the part of the programmer as with the explicit memory management in C++, and still the JVM has to look at each block during garbage collection to determine which ones are no longer used. Technically, there is nothing that prevents the implementation and use of garbage collection in C++ programs, and there are commercial programs and libraries available that offer this.But because of the dis favors mentio ned above, few C++ programmers make use of this. The Qt toolkit takes a more efficient approach to easing the memory management task for its programmers when an object is deleted, all dependant objects are automatically deleted too. Qts approach does not interfere with the programmers freedom to delete manually when they wish to. Because manual memory management burdens programmers, C and C++ have been accused of being prone to generate unstable, bug-ridden software.Although the danger of producing memory turpitude (which typically leads to program crashes) is certainly higher with C and C++, good education, tools and experience can greatly reduce the risks. Memory management can be learned like anything else, and there are a large government issue of tools available, both commercial and open source, that help programmers ensure that there are no memory errors in the program for example, Insure++ by Parasoft, Purify by judicious and the open source Electric Fence.C++s flexible me mory management system also makes it possible to write custom memory profilers that are adapted to whichever type of application a programmer writes. To sum up this discussion, we have found C++ to provide much better runtime- and memory-efficiency than Java, while having same programmer-efficiency. 2. 4. Available libraries and tools The Java platform includes an impressive number of packages that provide hundreds of classes for all kinds of purposes, including graphical user interfaces, security, networking and other tasks.This is certainly an improvement of the Java platform. For each package available on the Java platform, there is at least one alike(p) library for C++, although it can be difficult to assemble the various libraries that would be needed for a C++ project and make them all work together correctly. However, this strength of Java is also one of its weaknesses. It becomes increasingly difficult for the individual programmer to find their way through the huge APIs. For any given task, you can be almost certain that somewhere, there is 7A Comparison of Qt and Java functionality that would accomplish the task or at least help with its implementation. But it can be very difficult to find the right package and the right class. Also, with an increasing number of packages, the size of the Java platform has increased considerably. This has led to subsets e. g. , for embedded systems, but with a subset, the advantage of having everything readily available disappears. As an aside, the size of the Java platform makes it almost impossible for smaller manufacturers to ship a Java system independent from Sun Microsystems, Javas inventor, and this reduces competition.If Java has an advantage on the side of available libraries, C++ clearly has an advantage when it comes to available tools. Because of the considerable maturity of the C and C++ family of languages, many tools for all aspects of application development have been developed, including design, de bugging, and profiling tools. man there are Java tools appearing all the time, they seldom measure up to their C++ counterparts. This is often even the case with tools with the same functionality coming from the same manufacturer compare, for example, Rationals Quantify, a profiler for Java and for C/C++.The most most-valuable tool any developer of a compiled language uses, is still the compiler. C++ has the advantage of having compilers that are clearly superior in execution speed. In order to be able to ship their compilers (and other tools) on various platforms, vendors go to implement their Java tools in Java itself, with all the aforementioned memory and efficiency problems. There are a few Java compilers written in a native language like C (for example, IBMs Jikes), but these are the exception, and seldom used. 3. Comparing AWT/Swing and QtSo far, we have compared the programming language Java and the programming language C++. But as we discussed at the beginning of this ar ticle, the programming language is only one of the aspects to consider in GUI development. We will now compare the packages for GUI development that are shipped with Java, i. e. AWT and Swing, with the cross-platform GUI toolkit, Qt, from the Norwegian supplier, Trolltech. We have confined the comparision on the C++ side to the Qt GUI toolkit, since unlike MFC (Microsoft Foundation Classes) and similar toolkits, This seems to contradict Javas cross-platform philosophy and may be due to the the initial AWT version being reputedly developed in under cardinal days. Because of these and a number of other problems with the AWT, it has since been augmented by the Swing toolkit. Swing relies on the AWT (and consequently on the native libraries) only for very staple fibre things like creating rectangular windows, handling events and executing primitive drawing operations. Everything else is handled inside Swing, including all the drawing of the GUI components.This does away with the probl em of applications looking and behaving other than on different platforms. Unfortunately, because Swing is mostly implemented in Java itself, it lacks efficiency. As a result, Swing programs are not only slow when performing computations, but also when drawing and handling the user interface, leading to poor responsiveness. As mentioned earlier, poor responsiveness is one of the things that users are least willing to tolerate in a GUI application. On straight offs standard commodity hardware, it is not unusual to be able to watch how a Swing button is redrawn when the mouse is pressed over it.While this situation will surely improve with faster hardware, this does not address the fundamental problem that complex user interfaces developed with Swing are inherently slow. The Qt toolkit follows a similar approach like Swing, it only relies on the native libraries only for very basic things and handles the drawing of GUI components itself. This brings Qt the same advantages as Swing (f or example, applications look and behave the same on different platforms), but since Qt is entirely implemented in C++ and thus compiled to native code it does not have Swings efficiency problems.User interfaces written with Qt are typically very fast because of Qts smart use of caching techniques, they are sometimes even faster than comparable programs written using only the native libraries. Theoretically, an optimal native program should always be at least as fast as an equivalent optimal Qt program however, qualification a native program optimal is much more difficult and requires more programming skills than making a Qt program optimal. Both Qt and Swing employ a styling technique that lets programs display in any one of a number of styles, independent of the platform they are running on.This is possible because both Qt and Swing handle the drawing themselves and can draw GUI elements in whichever style is desired. Qt even ships with a style that emulates the default look-and -feel in Swing programs, along with styles that emulate the 9 A Comparison of Qt and Java Win32 look-and-feel, the Motif look-and-feel, andin the mack version the MacOS X Aqua style. 3. 2. Programming Paradigms In Qt and Swing While programming APIs to some extent are a intimacy of the programmers personal taste, there are some APIs that lend themselves to simple, short, and de luxe application code far more readily than others.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment