The friend I quoted yesterday sent me a better representation of his views. I apologize to all of you for not checking with him before quoting him. The following is that better representation, except for my questions or comments which have an _even_ number of '>': ** (If you're not interested in most of this, you still might want to scroll down to the part about "subtypes") ** > The "Purity" Measure > ==================== > > In my original comments I said Java was better than Ada because Java was a > pure OO language while Ada95 (and C++) were hybrids. > > > Some folks would say Ada-95 offers the best of both worlds and C++ the worst. :-) > > If I had to choose between Ada95 and C++ I would certainly choose Ada95. > Stroustrup is a genius but even a genius couldn't make C into a decent OO language. > > When I used Ada95 I did feel it was the best of both worlds. I felt that in > many situations an OO approach was not beneficial and it was nice to have a choice. > > OO purists would say that Java isn't a "pure" OO language. And it is certainly > possible to write non-OO code in Java; just make all your methods static. > > Conclusion: Java and Ada aren't really so far apart here after all. But I > still give Java a slight edge on the "purity" scale. If "purity" sounds too > subjective (and thus irrelevant) call it "consistency and ease of use." > > Dynamic Class Loading > ===================== > > > Many Ada fans (and myself) agree, except that dynamic loading is (1) a feature of > > the JVM, not the language, and (2) has been available in Unix for years, but > > never taken advantage of. > > Well, help me here. In Java, I can create an object at run-time whose class > didn't even exist at compile time. For example, I can prompt the user for a > String and then use that String as an argument in the Class.forName method. > Once I have the the Class object, I can call its newInstance method. I believe > the technical term for this is "Way Cool". That seems like a language feature > to me but I realize I may be missing something. Conceded. I was not aware of these Java features. And I think I would use the same technical term. You can do that in other languages, but it's certainly not easy. (I was once asked to work on a "Database Management System" which I discovered was a BASIC program that queried the user for names, types, and constraints of data fields, generated another BASIC program, and CHAINed to it. Ugggh!) > Garbage Collection I > ==================== > > > Real-timers are divided on garbage collection. In Ada, all garbage > > collection is automatic for what Java calls "primitive types". > > This is true of Java as well. Java primitive types are the types that are > handled like types in non-OO languages. I didn't mean to imply that it wasn't true of Java. Both of them reclaim stack on exit of scope. The difference is that Java limits it to a small set of non-OO types while Ada does it for everything not explicitly put on the heap. > > And for a > > heap-based type, one can define the garbage collection in the package that > > declares the (controlled) type, making it automatic for all clients. > > I concede that Ada offers much more flexibility here. This goes back to the > trade-off between language "size" and language features. > > Wacky C Syntax I > ================ > > > > * The economy of expression afforded by expression statements and the lack of > > > "end" statements in Java is easy to misuse but _can_ be used to advantage > > > also. Ada is a bit stilted. > > > > I find no advantage in writability over readability. However, with familiarity, > > the readability problem probably fades considerably. > > I suspect that objective observers would give this point to Ada. Writing > "C-style" code is a guilty pleasure, I guess. And as I hinted, most languages are perfectly readable to their experts. APL and some C may be exceptions. :-) > Pandering to the Masses > ======================= > > > > > * The biggest non-technical advantage of Java is that it is available! This is > > > because Sun has downplayed the innovative features of the language and sold it > > > as an improved C. I think Java is much better than that but Sun was clever > > > enough not to stress it. Ada got that wrong from a marketing point of view. > > > Ada bills itself as the language for doing software right, but, guess what, > > > nobody wants to do software right! > > > > I almost agree. Few people [not 'nobody'] want to "do software > > right" As one of those few, I still like Ada better than Java (and > > I wish I had occasion to learn Eiffel). > > Specifications compilable before implementation > =============================================== > > You and I agree this is deficiency of Java. Now that I think of it, though, > you can achieve a similar effect in Java with abstract classes and with > interfaces. But Ada's compilable specs are a simple, powerful, proven > language feature that the rest of the world will eventually have to recognize. > > Enumerated types, non-Zero-Based Array Indices > ============================================== > > We basically agree that it would be nice if Java had these. > > Garbage Collection II > ===================== > > Certainly Ada is more flexible here. And in real-time applications Ada's > advantage can be significant. If I was doing an embedded real-time project > with demanding timing and/or memory requirements, I would certainly be ready > to go back to Ada95! > > Object Equality > =============== > > > I find it rather non-intuitive and awkward that in most cases, assignment > > and comparison operators relate to the references, not to the actual > > object or value. The rarely needed operation is the easiest to read and > > write, while the common one is more awkward and often doesn't even exist > > until defined by the programmer. Apparently the author of my Java book > > thinks so, too. It's also a readability problem that you have to think > > about whether the types are "primitive" to know which of two meanings to > > read for an operator. This is contrary to Java's argument against > > operator overloading! > > As a teacher of Java as well as a user, I agree this is an unfortunate > confusion in Java. Of course it all makes sense once you get used to it, > but I guess that's what people say about C and C++ wacky features. > > Wacky C Syntax II > ================= > > > Not possible to "forget" to put "break" in a case statement. > > > > I agree that this is an amazingly stupid C characteristic not fixed in Java. > > Subtypes [READ THIS ONE!] > ======== > > > Types and subtypes whose ranges relate to the abstraction, not to the > > implementation. (Can do it in Java, but only with a lot of OOP > > baggage.) > > Ya know, a lot of what we're saying here has been said a million times already > and I'll bet a lot of people stopped reading this message paragraphs ago... > _but_ I think this issue of subtypes deserves some real attention. > > I used to be a big believer in subtypes and I couldn't understand how C > programmers lived without them. But I saw subtypes get really abused on a > large Ada project and now I don't know what to think. I'd like to hear some > other opinions. I must confess that much of the Ada code I've seen has been written by people without adequate Ada training. My viewpoint is teach people how to use the feature instead of forbidding it--but then, that's what C fans say about Ada! :-) > Fixed sizes for primitive numeric types > ======================================= > > > > As for int being 32 bits, that's tied to small and simple again. I thought it > > > was a daring, bold, and positive move for Java to just _decide_ that ints were > > > such-and-such a size, period. > > > > This was definitely a good idea for C programmers who insist on writing > > size-dependent code even though they know it's not portable. On the other > > hand, if you write in terms of requirements or abstractions (as Ada > > allows), your code is portable to any compiler that supports the ranges or > > other details that you've specified--and other compilers won't compile > > it! > > Operator overloading > ==================== > > > Since Java does not allow putting range constraints on primitive types, > > anyone who wants it has two choices: > > a. Explicitly write your range checks everywhere you do anything with the type. > > b. Write a class that always does it's own range checking, and give up > > infix notation for your expressions. A * B + C * D becomes > > Sum_Of(Product_Of(A,B),Product_Of(C,D)) Plus you have to write all > > the operators your clients might need--even though the comparisons > > need no range checking. This is one spot where the philosophies are > > reversed: Java takes away a valuable capability because programmers > > abused it. Ada allows it even though there's no way to force the > > programmer to give the operator the "intuitive" meaning. > > Yes, well, I hear you. > > Access-to-subprogram that is fully type safe and nesting safe > ============================================================= > > > the inventors of Java AND of Ada 83 > > rejected access-to-subprogram because it wasn't safe. But in Ada 95, so > > many people demanded it that we figured out a way to MAKE IT SAFE. Java's > > inventors either didn't know this could be done, or they thought it would > > make the language "large." > > I know Ada95 has type-safe procedure references (oops, I mean accesses!). But > I don't think Java has a problem here. In Java, procedure references are > "passed" by using interfaces. I think it's type-safe, but help me out here. You're probably right. I haven't gotten to "interfaces" in my book, so I really don't (obviously) understand them. Something earlier in the book suggested that Java "rejected access-to-subprogram because it wasn't safe." (not in those terms) > Tasking > ======= > > The usual points... > > The OOP inheritance mechanism is independent of the encapsulation mechanism > =========================================================================== > > > (Lack of this is why C++ had to have the dangerous > > "friends" feature. Does Java have something like that?) > > I had written: > > > Actually I think Java and Ada are tied on this one. Java packages are > > > independent of inheritance. > > > I don't know what the connection is. I was referring to the fact that two > > Java classes cannot share private data like two or more Ada types in one > > Ada package. In Java, the methods and instance variables are encapsulated > > within the class, which corresponds to ONE Ada type as well as ONE Ada > > package. This is not major, though, since mutually dependent types are > > not that often needed and Java does have some workarounds. > > I still think Java has this covered. Non-public classes and methods I declare > in a Java package are only visible within the package. Java programmers don't > think this way but it _is_ a natural use of Java packages to put two public > classes in a package along with all kinds of non-public classes. Nobody > outside the package would be able to access the non-public classes. I don't > think this is a "workaround"; I think it's a significant Java language feature > intentionally provided to give Java programmers the same capability that is > available in Ada. It's just that most Java programmers don't understand the > _advantages_ of this kind of encapsulation. I guess I'll have to wait on this one till I finish the Java book. I don't know anything about Java packages. I was basically parroting the complaints I had heard from others that you can't easily have mutually-dependent data types in Java.