News for hackers. Stuff that matters.
Re:Java Was Strongly Influenced by Objective-C by AdieuToLogic on Thursday June 25, 2015 @11:30PM (#9782328)
I believe the similarities you find between Java and C++ are entirely intentional. But I respectfully disagree with:

> 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...

Re:Java Was Strongly Influenced by Objective-C by vbezhenar on Saturday June 27, 2015 @04:17PM (#9791403)
> * As you said, all Java classes inherit from a common type; java.lang.Object (Smalltalk).

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.

Re:Java Was Strongly Influenced by Objective-C by AdieuToLogic on Sunday June 28, 2015 @11:21PM (#9796253)
Your itemized explanations of what can be done in C++ only reinforces that the environments are quite different.

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.

2 - http://shop.oreilly.com/product/9781565925670.do

2 - https://common-lisp.net/project/ecl/