"Dan" == Dan Busarow <dan@dpcsys.com> writes:
Dan> At Usenix 96 in San Diego it was pointed out that applets are Dan> an abberation. This is a complete language designed to Dan> displace C++, Visual Basic and other OO languages. Thinking Dan> of Java as simpy a Web enhancement tool is short sighted. Dan> Personally it is more attractive than C++ for product Dan> development and we are trying to get it on FreeBSD, SCO Dan> UnixWare and SCO OSR5. Using Java for applets _only_ is like Dan> @#$% your mother... Most of us are not into it. I have been doing work in Java for the past half a year or so (most recent project: implementing SSL 3.0). I can't say I don't like it at all, but I like C++ much more. Here are my thoughts about the issue. Since there is a subjective component to choosing a programming language, flamewars are very likely to erupt when you say "Language A is much better than Language B", but it may still be interesting to read others' opinions. As I see it, Java as a language is basically (C++) + (garbage collection) - (templates) - (operator overloading) - (multiple inheritance) - ... Garbage collection is a very useful thing in many cases (though in some it may be a great slowdown), but there is no real reason not to incorporate GC into a C++ implementation, or at least give the user an option of doing it. On the other hand, templates are an extremely useful feature, since they allow huge amounts of code reuse (Wei Dai's crypto++ library is a great example of the use of templates). They also enable a C++ programmer to do such things as run-time array boundary checking (refuting one of the traditional arguments about the dangers of C++), or a type which is a subrange of another. Java programs can have some template-like functionality through the use of the Object class, but that is very limited. For instance, compare the following hypothetical Java code List l; l.append(new Integer(1)); l.append(new Integer(2)); int x = ((Integer)(l.head())).intValue(); with this C++ List<int> l; l.append(1); l.append(2); int x = l.head(); The second version is clearly more readable. It would also be more efficient since no run-time conversions would be done. There are also situations in which templates would work, but Objects would not. For instance, it is very easy in C++ to make a template class Range<type, min, max> that would be a subrange [min, max] of type, and would do run-time checks for any assignments. There is no way you can do this in Java. Java also lacks operator overloading. 'V = M*W + A' (where V, W, and A are vectors, and M is a matrix) is much easier to read than 'V = Vector.add(Matrix.multiply(M, W), A)'. The same would apply to a big integer class. The lack of multiple inheritance is somewhat alleviated with the use of interfaces, but there are cases where this is not enough. The crypto++ library uses a lot of nontrivial multiple inheritance. Another strange deficiency of Java is that there is only one way to pass parameters. All class parameters are passed by reference, while all primitive-type parameters are passed by value. What if you need to pass an integer by reference? Also, when you pass a class parameter, the method can modify it arbitrarily, since Java does not allow constant variables. As for the usual complaint "C++ has pointers which are unsafe!!!", the following can be said. First, Java has pointers too: all class objects are actually pointers to data, so, for instance, "A = B" in Java would mean "Make A a pointer to the same location as B", not the traditional meaning "Make A a copy of B". Second, when it is said that C++ pointers are unsafe, usually two things are meant: C++ allows you to cast a pointer of one type to a pointer of another type, and C++ allows for pointer arithmetic. Both of these features are not needed in virtually all programs (they were probably retained only for C compatibility), except those that interface with the low-level system calls. Also, both of them can only be invoked explicitly. Thus, the programmer which uses them has only himself to blame if anything goes wrong. In summary, I don't see Java as the new great language that is going to replace C++ in the standalone application arena, even if Java ran as fast as C++. It is true that Java has a nice standard library (including threads), but there is no reason whatsoever why a library with a very similar interface could not be written in C++. On the other hand, considering Java as a language specifically for applets is a completely different matter. Here it does not compete with C++. The competitors -- Safe-Perl, Python, and Safe-TCL (and perhaps some Scheme-like languages) -- don't stand a chance without being supported by Netscape. Thus I would say that Java became so popular for the following reasons: - It was developed by Sun. - It was licensed by Netscape. - It is C++ -like. - JDK (and its source) were made freely available. Constructive comments and discussion of this issue would be appreciated, but send the flames to /dev/null. Sincerely, Victor Boyko -- Victor Boyko <vboykod@is-2.nyu.edu> http://galt.cs.nyu.edu/students/vb1890/ To get my PGP key, finger or send e-mail with subject "send pgp key".