Hacker News new | past | comments | ask | show | jobs | submit login

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




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/




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: