Java Was Strongly Influenced by Objective-C
cs.gmu.edu
cs.gmu.edu
Even back in the '90s, when I wrote that as a wee PhD student, it was clear that Java was derivative of Obj-C (among others) much more than C++.
EDIT: all the Newton references in that passage are because it was posted in comp.sys.newton.misc (IIRC).
But my question is, what modern language today is a copy of Dylan?
Of the languages created at Apple, Dylan was the most interesting one. Swift is practical in many ways, but it's not inspired or visionary.
Swift is basically a better C++ with decent Cocoa interop built-in. It's comparable to C# in originality... And that's not putting down either Apple or Microsoft -- it's simply the realities of creating a language at a large corporation with internal and external stakeholders.
But novelty just for the sake of novelty... yeah, not so much.
> Objective-C is an object-oriented mutant of C
But Java (the language) has little in common with C++ aside from the token-level commonality both share with B.
As for Java's interfaces, those (as "zak_mc_kraken" mentions) have strong ties to Objective-C's protocols, though I disagree with the subsequent statement of them being "a simplification of C++'s multiple inheritance". IMHO, they are far closer to C++'s class/function declarations.
I'd say Java had a similar influence as C++ did from Simula, introducing superficial similarities with C++ due to its dominance at the time[2], but incorporated more of the dynamics provided by Smalltalk-like languages (such as Objective-C). Note the use of "super" for calling parent methods and the lack of multiple inheritance in both.
1 - http://www.virtualschool.edu/objectivec/
2 - Fun bit of trivia: when Java hit the scene in the late 90's, you could globally replace the word "reference" with "pointer" and the documentation would read just the same. See section 2.2.9 of http://www.oracle.com/technetwork/java/simple-142616.html for a prime example.
So Java "reference" is C++ pointer without asterisks and ->. All java methods are virtual. Java interface is full-abstract class without fields (in Java 8 even not so full-abstract). Multiple inheritance only with interfaces. No generics (I learned Java 1.4), one common ancestor Object, friendly GC releasing you from the pain of memory management.
Basically the only new concept is package. Otherwise it's stripped C++ with different runtime library.
Today, these decisions would have been different, as C++ no longer reigns supreme. I find that Kotlin has completely adopted all of Java's core values, but modernized the specific syntax and semantics. Kotlin is what Java would have been if it had been designed today. The fact that Kotlin has made interoperation so seamless (you can switch any single Java class with a Kotlin file in an existing project -- IntelliJ would even automatically translate it for you) makes transitioning from Java to Kotlin (if you want) so smooth and gradual that it's a tru pleasure (even working on a mixed codebase).
[1]: http://www.win.tue.nl/~evink/education/avp/pdf/feel-of-java....
OTOH - where are the named parameters in Java method calls?
The creators had Objective C in mind, but the result is so stripped down, it becomes an ink blot test for the viewer to see what they want :-)
I sure as hell don't see "Eiffel", though. JavaBeans are evil.
Not sure where you got that from... the notion of a class being a "reference type", which is the foundation of Java, doesn't even exist in C++. Every class type is a value type in C++.
The only difference is that Java's subset also does not include pointer arithmetic, so this is actually a safe coding practice, because it allows for garbage collection to be performed.
Yes, C++ can emulate what Java is doing, but no, that's not what I'm saying. I'm saying C++ classes are not reference types, i.e., every class you define is always a value type, which is the exact opposite of Java. Obviously C++ also has pointers/references that could help you emulate Java, but that's beside the point. The point is that classes work differently in C++ and Java, and neither functionality is a subset of the other.
class MyClass_ { ... }
typedef MyClass_ *MyClass;
and you have identical "reference" semantics in C++. Of course you have to use `->` instead of `.`, but does it matter?More than Microsoft, I think Java killed Borland. Java had no IDE back in 95/96, but the compiler was free and it also ran on Linux, which Borland was late to adopt.
... then Anders went to work for Microsoft, and the rest is tragedy.
float a = 1.0; // compilation error in java, no problem in C++
For another: int a[5] = { 0, -1, 2, 3, 4 };
(1+a) = 1; // :)
Also: assert( !(1/2) );
Also: enum Foo {A, B};
enum Bar {C, D};
Foo e1 = A;
Bar e2 = C;
int i = 0;
assert(e1 == e2); // warning
assert(e1 == i); //no problem whatsoeverI will concede that the others are problematic...
*(1+a) = 1;
Still bad but not as bad. 1[a] = 1;I learned Java and C++ at the same time. And I had a hard time doing it because I believed Sun's marketing department that Java was a better C++. When I finally realized that was a classic bit of puffery, and that the marketing was simply trying to make Java look powerful by association with C++, I was able to make some progress.
Before then java wasn't so bad.
List doSth(Object a, Object b) { ... }Scala pretends to solve this problem by "layering" code. Complex types are for libraries and users should use libraries. But IMO it never worked. Problems arising, "users" have to debug into library code and they have to deal with full-featured types anyway.
My only real wish in regard to Java 1.4 was that I would be able to implicitly cast Object to anything (like I can in Objective C). That would help to reduce type clutter a lot.
From my perspective that's the large difference between Java and Scala. In Java, complexity leaks into the use-site (especially with Generics), in Scala it's possible to shield the user from that complexity.
> Java is basically a subset of C++ with some sugar around.
Here are a few reasons why:
* As you said, all Java classes inherit from a common type; java.lang.Object (Smalltalk).
* Inner classes automatically have a reference to the containing class (not in C++, though Java "nested classes"[1] behave similar to C++ structs/classes).
* java.lang.ClassLoader has no corresponding abstraction in C++.
* C++ has pass-by-reference semantics which is completely missing in Java.
* C++ supports destructors intrinsically.
* All definitions must exist within a type in Java. There is no concept of a "free standing" definition.
* Java provides meta-objects by way of java.lang.Class for all classes (not present in C++).
* Java does not support stack-based allocation except for built-in POD's.
> Java interface is full-abstract class without fields (in Java 8 even not so full-abstract). Multiple inheritance only with interfaces.
A Java interface has a distinct type within the type system, yes, and there exist meta-objects describing them generated as well. But until Java 8, interfaces had no behaviour and could only declare static fields.
> So Java "reference" is C++ pointer without asterisks and ->.
Pretty much.
As an aside, it has always cracked me up that a language touted as having no pointers has a "NullPointerException" class. (I am easily amused)
1 - http://docs.oracle.com/javase/tutorial/java/javaOO/nested.ht...
You can limit yourself in C++ to inherit your objects from a common type. I believe that Qt did just that, for example. So this is a subset of C++.
> * Inner classes automatically have a reference to the containing class (not in C++, though Java "nested classes"[1] behave similar to C++ structs/classes).
That's a good example of simple sugar. Inner class just have pointer to the outer class and constructor with this parameter. Java compiler emits this code automatically. Yes, there's no such thing in C++, but it's very simple to emulate.
> * C++ has pass-by-reference semantics which is completely missing in Java. > * C++ supports destructors intrinsically. > * All definitions must exist within a type in Java. There is no concept of a "free standing" definition. > * Java does not support stack-based allocation except for built-in POD's.
Yes, Java is subset of C++ in that regard. C++ has more features which were stripped out.
> * java.lang.ClassLoader has no corresponding abstraction in C++. > * Java provides meta-objects by way of java.lang.Class for all classes (not present in C++).
Actually those systems could be emulated more or less in C++. Windows does have COM (and there are a lot of less known, but similar systems) which allows to dynamically load classes with virtual methods, etc. Qt implements (with some preprocessor magic) reflection for C++. But generally yes, C++ does not have any kind of runtime reflection (except dynamic_cast) and dynamic code loading, I agree here. What I want to point out is, that those features are provided by JVM. Java as a language does not have anything related to reflection or class loading. So probably it's not fair to compare Java + JVM to C++.
> As an aside, it has always cracked me up that a language touted as having no pointers has a "NullPointerException" class. (I am easily amused)
That's very unfortunate mess of terms. Pointers should be pointers, even if there's no pointer arithmetic in the language. Now we have pointers, references, pass-by-reference and beginners having hard time to understand what that even mean.
One of the wonderful things about C++[1] is that it can express just about anything which can be encoded in a program. GC, common base types, functional programming, imperative programming, object oriented programming, meta-programming, logic-based systems, dynamic module systems (a la Apache modules[2]), and a bunch more.
But that does not make a language such as Java a subset, unless your premise is that any language which can in some way be expressed in or embedded int C++ qualifies as a subset. If that's the case, then pretty much every language "is a subset of C++" (and yes, even Lisp[3]).
1 - Yes, I mean "wonderful things" as I have worked in C++ for many years. Still do when the problem calls for it.
Depending on which angle you look at, you could see Java's interfaces as a direct successor of Objective C's protocols or a simplification of C++' multiple inheritance.
If you were to believe James Gosling, it's clearly the latter that influenced Java's design. The fact that Naughton liked Objective C hasn't had much impact on what Java ended up looking like in 1995.
In terms of how you program, Java is a lot more like C++, minus half the language features that make C++ both powerful and dangerous. Obviously there are fundamental differences, but I think it's pretty clear that someone switching from C++ to Java would have a much easier time adjusting, then going from C++ to Objective-C.
Also, I find the qualification of Objective-C as a 'mutant of C' a bit off the mark. Yes, Objective-C is a superset of C, it's built on exactly the same foundation, but the end result is and how you use it is completely different in almost everything except the syntax of the pure C-constructs and fundamental types.
That and making 'byte' signed.
It's true that if you spend a lot of time in Java these things fade into the background, but these are exactly the things that shouldn't fade. You'll never "whip up a quick script" in Java because of these problems.
Personally I think the tooling is the best part of Java. Having an IDE helps you build more robust software by providing far more context than a text editor ever could. The build systems have reached the point that its very easy to do the right thing to build robust software. Compared with what came before (make, imake, configure etc) the tools are much better.
Also, yes, I whip up quick scripts in Java all the time, because sometimes it's the closest hammer to my particular nail. Your entire comment can be summed up as "I don't really understand Java, and I don't like it" which is not a terribly compelling argument.
1) You have no way of knowing that your category method isn't going to collide with another method. That method could be one of Apple's private ones, or it could be a method from a category used by another library you included in your app, or it could be even be from a category used in a jailbreak tweak. In all these cases, it's entirely possible that the colliding method doesn't have the same size arguments or return type as yours, in which case you are going to get extremely difficult to debug crashes. You also don't have guarantees around whose categories win.
2) As a class developer, you have no way of preventing categories from messing up internal guarantees of your class. Want it to be immutable? Too bad, some developer you've never talked to added methods in a category that require local state. Want to add and use a new private method? Too bad, that name is already taken by some random category, and now it looks like your code is breaking everything because it was just committed.
Prefixing category methods is a partial fix, but lots of folks aren't aware that they should do that.
That said: Swift extensions are safer because private categories cannot collide.
Haxe and Scala (and probably many others) have a nice solution to this problem. You can add "methods" to existing classes but only you can see them. You never really change the semantic of something that does not belong to you.
But I've come to appreciate that it can greatly improve readability when trawling through unfamiliar code bases, and thankfully it's a feature Apple have carried across to Swift.
Now days I often wish Java had external parameter names, too!
Most people tend to react to it really negatively at first encounter though.
Converting that piece of Java codes into ObjC was easy and straightforward because it was basically just some Foundation classes, e.g. NSString, NSArray, NSDictionary and NSNumber.
That's like the opposite of finding out that Sweden named New York
Wikipedia says J#, but I think this is a later incarnation: https://en.wikipedia.org/wiki/Comparison_of_C_Sharp_and_Visu...
"The keywords const and goto are reserved by Java, even though they are not currently used in Java. This may allow a Java compiler to produce better error messages if these C++ keywords incorrectly appear in Java programs."
[1] http://titanium.cs.berkeley.edu/doc/java-langspec-1.0/3.doc....
"Object-Oriented Programming: An Evolutionary Approach" ISBN-10: 0201548348 ISBN-13: 978-0201548341
"Superdistribution: Objects as Property on the Electronic Frontier" ISBN-10: 0201502089 ISBN-13: 978-0201502084
even after all these years, they still give some interesting insights
Funny to see the 'oak' name reused - it's now an Apache project for a jcr backend.
EOUtilities.objectsMatchingKeyAndValue(key, value);
You can still see a lot of the original code in Project Wonder e.g.https://github.com/wocommunity/wonder/blob/master/Frameworks...
Work with WO made me prefer this style of long, self documenting method/variable names.