| |
| ▲ | igouy 3 hours ago | parent | next [-] | | > everything must be an object when there are many other useful way to program. Perhaps you would prefer a multi-paradigm programming language? http://mozart2.org/mozart-v1/doc-1.4.0/tutorial/index.html | |
| ▲ | kragen 5 hours ago | parent | prev [-] | | Java was derived from C++, Smalltalk, and arguably Cedar, and one of its biggest differences from C++ and Smalltalk is that in Java things like integers, characters, and booleans aren't objects, as they are in C++ and Smalltalk. (Cedar didn't have objects.) | | |
| ▲ | bluGill 5 hours ago | parent [-] | | Right. Everything a user can do is object, but there are a few non-object built ins. (they are not objects in C++ either, but C++ doesn't make everything you write be an object) | | |
| ▲ | kragen 5 hours ago | parent [-] | | In C++ integers and characters are objects. See https://en.cppreference.com/w/cpp/language/objects.html, for example, which explicitly mentions "unsigned char objects", "a bit-field object", "objects of type char", etc. | | |
| ▲ | dpark 4 hours ago | parent | next [-] | | I feel this is a case of using the same word to mean something different. C++ “object” here seems to mean something more akin to “can be allocated and stuffed into an array” than a Smalltalk-type object. i.e. C++ primitive types are defined to be objects but do not fit into a traditional object-oriented definition of “object”. | | |
| ▲ | kragen 4 hours ago | parent [-] | | Yes, many people believe that C++ isn't really "object-oriented", including famously Alan Kay, the inventor of the term. Nevertheless, that is the definition of "object" in C++, and Java is based on C++, Smalltalk, and Cedar, and makes an "object"/"primitive" distinction that C++, Smalltalk, and Cedar do not, so "Java [did something] by deciding everything must be an object" is exactly backwards. | | |
| ▲ | bluGill 3 hours ago | parent | next [-] | | I'm not sure who invented "object oriented", but objects were invented by Simula in 1967 (or before, but first released then?) and that is where C++ takes the term from. Smalltalk-80 did some interesting things on top of objects that allow for object oriented programming. In any case, Alan Kay is constantly clear that object oriented programming is about messages, which you can do in C++ in a number of ways. (I'm not sure exactly what Alan Kay means here, but it appears to exclude function calls, but would allow QT signal/slots) | | |
| ▲ | kragen 3 hours ago | parent [-] | | The specific thing you can do in Smalltalk (or Ruby, Python, Objective-C, Erights E, or JS) that you can't do in C++ (even Qt C++, and not Simula either) is define a proxy class you can call arbitrary methods on, so that it can, for example, forward the method call to another object across the network, or deserialize an object stored on disk, or simply log all the methods called on a given object. This is because, conceptually, the object has total freedom to handle the message it was sent however it sees fit. Even if it's never heard of the method name before. | | |
| ▲ | bluGill 15 minutes ago | parent [-] | | You can do that in C++ too - it is just a lot of manual work. Those other languages just hide (or make easy) all the work needed to do that. There are trade offs though - just because you can in C++ doesn't mean you should: C++ is best where the performance cost of that is unacceptable. | | |
| ▲ | kragen 3 minutes ago | parent [-] | | No, in C++ it's literally impossible. You have to generate a fresh proxy class every time you have a new abstract base class you want to interpose. |
|
|
| |
| ▲ | dpark 3 hours ago | parent | prev [-] | | To be clear, I’m not trying to pick at whether or not C++ is “really object oriented”. What I’m saying is that the discrepancy between primitives in C++ and Java is entirely one of definition. Java didn’t actually change this. Java just admitted that “objects” that don’t behave like objects aren’t. | | |
| ▲ | kragen 3 hours ago | parent [-] | | On the contrary, Java objects are very different from C++ objects, precisely because they lack a lot of the "primitive-like" features of C++ objects such as copying, embedding as fields, and embedding in arrays. (I'm tempted to mention operator overloading, but that's just syntactic sugar.) | | |
| ▲ | dpark 3 hours ago | parent [-] | | Java differs from C++ in an endless number of ways. What I’m saying is that in both C++ and Java, there are a set of primitive types that do not participate in the “object-orientedness”. C++ primitives do not have class definitions and cannot be the base of any class. This is very much like Java where primitives exist outside the object system. If the C++ standard used the term “entities” instead of “objects” I don’t think this would even be a point of discussion. | | |
| ▲ | kragen 2 hours ago | parent [-] | | It's not some minor point of terminology. The entire design of C++ is built around eliminating all distinctions between primitive "entities" and user-defined "entities" in a way that Java just isn't. It's true that you can't inherit from integers, but that's one of very few differences. User-defined "entities" don't (necessarily) have vtables, don't have to be heap-allocated, can overload operators, can prevent subclassing, don't necessarily inherit from a common base class, etc. C++'s strange definition of "object" is a natural result of this pervasive design objective, but changing the terminology to "entity" wouldn't change it. | | |
| ▲ | dpark 2 hours ago | parent [-] | | > The entire design of C++ is built around eliminating all distinctions between primitive "entities" and user-defined "entities" If the intent was to erase all distinction between built-in and user-defined entities then making the primitive types unable to participate in object hierarchies was a pretty big oversight. But at this point I think we’re talking past each other. Yes, in Java objects are more distinct from primitives than in C++. But also yes, in C++ there is a special group of “objects” that are special and are notably distinct from the rest of the object system, very much like Java. | | |
| ▲ | kragen 2 hours ago | parent [-] | | You can read Stroustrup's books and interviews, if the language design itself doesn't convey that message clearly enough; you don't have to guess what his intentions and motivations were. And, while I strongly disagree with you on how "special and notably distinct" primitive types are in C++, neither of us is claiming that C++ is less adherent to the principle that "everything is an object" than Java. You think it's a little more, and I think it's a lot more. But we agree on the direction, and that direction is not "Java [did something] by deciding everything must be an object," but its opposite. | | |
| ▲ | dpark an hour ago | parent [-] | | I don’t actually think it’s any more adherent to that notion. This is exactly why I tried to point out the discrepancies in definitions. You have to define what an “object” is or the discussion is meaningless. If the definition of object is something like “an instance of a class that has state, operations, and identity” then C++ primitives are fundamentally not objects. They have no identity and they are not defined by a class. If “participates in a class hierarchy” is part of the definition, then C++ is way less OO than Java. I don’t quite understand what your definition is, but you seem to be arguing that user-defined entities are more like primitives in C++, so it’s more object-oriented. So maybe “consistency across types == object orientedness”? Except C++ isn’t really more consistent. Yes, you can create a user-defined type without a vtable, but this is really a statement that user defined types a far more flexible than primitives. But also if “consistency across types” is what makes a language OO then C seems to be more OO than C++. | | |
| ▲ | kragen an hour ago | parent [-] | | I don't think C++ is object-oriented, and it is certainly way less OO than Java in most ways. Its "classes" aren't the same kind of thing as classes in OO languages and its "objects" aren't OO objects. In part this is because by default even C++ class instances don't have identity, or anyway they only have identity in the sense that ints do, that every (non-const) int has an address and mutable state. You have to define a destructor, a copy constructor, and an assignment operator to give identity to the instances of a class in C++. With respect to "participates in a class hierarchy", that has not been part of the definition of OO since the Treaty of Orlando. But, in Java, all objects do participate in a class hierarchy, while no primitives do, while, in C++, you can also create class instances (or "class" "instances") that do not participate in a class hierarchy (without ever using inheritance, even implicitly). So, regardless of how OO or non-OO it may be, it's another distinction that Java draws between primitives and class instances ("objects" in Java) that C++ doesn't. |
|
|
|
|
|
|
|
|
| |
| ▲ | bluGill 3 hours ago | parent | prev [-] | | Just like Java, you cannot inherit from integers or characters. Depending on what you want to do with them that might or might not matter. | | |
| ▲ | kragen 3 hours ago | parent [-] | | That's true, and in Smalltalk it's not true. In Cedar there is no inheritance. At any rate it's not a case of Java making more things objects than its forebears. |
|
|
|
|
|