8

I am interested in understanding object-oriented programming in a more academic and abstract way than I currently do, and want to know if there are any object-oriented concepts Java and C++ fail to implement.

I realise neither of the languages are "pure" OO, but I am interested in what (if anything) they lack, not what they have extra.

2
  • 16
    That would entail you spelling out what you mean by "OO".
    – anon
    Mar 16, 2010 at 19:34
  • 2
    I think the point is that OP doesn't know exactly what it means and wants something mind-expanding.
    – Ken
    Mar 16, 2010 at 22:29

9 Answers 9

15

In the words of Alan Kay, the inventor of the term "object orientation":

OOP to me means only messaging, local retention and protection and hiding of state-process, and extreme late-binding of all things. It can be done in Smalltalk and in LISP. There are possibly other systems in which this is possible, but I'm not aware of them.

C++ obviously fails the "extreme late-binding" criterium, and both Java and C++ fail the "messaging" criterium, due to their rigid class/method structure. As I understand it, Kay's concept considers methods with a specific name and signature a convenient way to implement message handlers, but by no means the only one.

Other interesting statements from the same email:

I didn't like the way Simula I or Simula 67 did inheritance [...] So I decided to leave out inheritance as a built-in feature until I understood it better.

and

The term "polymorphism" was imposed much later (I think by Peter Wegner) and it isn't quite valid, since it really comes from the nomenclature of functions, and I wanted quite a bit more than functions.

13
  • 1
    Doesn't Java also fail the former criterion?
    – Ken
    Mar 16, 2010 at 19:41
  • 2
    One important word here is "all" things. In Smalltalk-71, for example, syntax was late-bound. In later versions of the language, Smalltalk actually became a lot more static, which is why Alan Kay wanted to start over with a completely new approach. In fact, Smalltalk-76 and onwards were no longer designed by him, and they do not fully embody his vision of OOP, and neither do their successors, like Ruby. The language he is currently working on, is much more late-bound and dynamic than either Smalltalk or Lisp, where in fact even the definition of "late-bound" itself is late-bound. Mar 16, 2010 at 20:09
  • 1
    @Jörg W Mittag: sounds kinda cool. What is the name of that language? Mar 16, 2010 at 20:20
  • 1
    @FrustratedWithFormsDesigner: I don't think it has a name yet. You can find some information at the Research Institute that Alan Kay founded: VPRI.Org Also, just like Smalltalk it's not just a language, it's an entire Personal Computing System, consisting of an Operating System, Drivers, Graphical User Interface, Language, Compiler, Office Suite, Desktop Publishing, Networking, ... And the amazing thing: all of that in less than 20 thousand lines of code. Look at the papers on the VPRI website, or one of the videos on the web. Mar 16, 2010 at 21:02
  • 2
    People don't get just how OO Smalltalk was. In Smalltalk, the equivalent of new Foo() is Foo new. But it's not, really - in fact, in Smalltalk, that is a message sent to the singleton object Foo, which is a Class object. In Smalltalk, if is a message sent to an object. Java and C# say everything is an object... Smalltalk means it.
    – kyoryu
    Mar 19, 2010 at 5:31
8

Off the top of my head, I'd say:

3

Both make a distinction between primitives and objects, so neither are purely object-oriented.

1
  • 1
    @JRL: that's in no way "lacking a feature" and the question especially states that the poster knows that C++ and Java aren't pure OO languages. Mar 16, 2010 at 19:55
2

There's another way of thinking about object oriented programming that differs from the class-based system in Java and C++. Prototype based programming is used by JavaScript. If you want to look at the full gamut of OOP styles, it's probably worth taking a look at: http://en.wikipedia.org/wiki/Prototype-based_programming

1

Java : Primitive types are not objects.

7
  • 1
    That's not a feature that's lacking, it's a language design idiosyncrasy.
    – Benson
    Mar 16, 2010 at 19:41
  • 1
    Well, some people (me) call bugs missing features :) Mar 16, 2010 at 19:43
  • 1
    You can't write class MyInt: public int in C++ either. Not if you want it to compile, anyway. Mar 16, 2010 at 19:54
  • 1
    You can think of it as a multirooted hierarchy if you like. :) Mar 16, 2010 at 19:56
  • At least since java 1.5 there is autoboxing allowing easy interchange of for example int primatives with Integer objects. I agree though that it prevents java from being, in the strictest sense, a fully Object Oriented language
    – Alb
    Mar 16, 2010 at 20:28
1

Java doesn't have multiple inheritance, but some might say this is more of a blessing as it requires users to think of correct architecture. You can use interfaces and abstract classes to get around this.

Multiple inheritance has been criticised for the following problems that it causes in certain languages, in particular C++:

  • Semantic ambiguity often summarized as the diamond problem.
  • Not being able to explicitly inherit multiple times from a single class
  • Order of inheritance changing class semantics
2
  • @Chris Dennett: this is simply not true. Implementation is a detail and you need to know that you can trivially translate any OOA/OOD using any crazy multiple inheritance very cleanly in Java (as you can do in language that don't even have the concept of implementation inheritance) using multiple interface inheritance. You're probably confused with "code reuse" which you can trivially achieve using delegation. 200KLOC Java codebase here where we're using exactly zero time implementation inheritance... And where we use multiple inheritance everywhere. Mar 16, 2010 at 19:59
  • 1
    OK, WizardOfOdds, Java is missing the interface delegation. If you want some class to delegate interface I to object O, you have to manually create all the methods of I that just trivally call the same methods of O.
    – Gabe
    Mar 19, 2010 at 5:00
1

The single most important feature of object oriented programming is encapsulation. Hiding implementation details is obviously crucial to writing maintainable code.

In C++, since you have uncontrolled pointers, it is possible for one badly written object to do literally anything to another. This means that encapsulation is broken, and that bugs are difficult to find.

Java doesn't have that problem, but it lacks basic const-ness. That's not strictly an object-oriented theoretical feature, but being able to declare that a method is read only, or that an object is read only, is a fantastic reliability enhancer in C++ that is not in Java.

Last, java's template mechanism is a pale imitation of C++. Not being able to parametrize classes is a huge loss for Java.

Because Java doesn't support pointers to methods, and reflection is too slow, it forces the use of many little objects when a function pointer would do. Some may consider that a good thing.

0

Java and C++ both allow procedural programming. That can be considered to be a minus for some people.

1
  • 1
    I'd in fact argue that most Java/C++ code is procedural, with an OO veneer on it.
    – kyoryu
    Mar 19, 2010 at 5:32
0

Most interpreted languages meet the late-binding requirements. In Perl you can pull code out of a database table, throw it into the interpreter, then instantiate objects of the new class you've just introduced into the program.

Does Python fully meet Kay's definition of OOP? I've not done enough work in Python to be sure. I suspect not, since Python has 'native types' that are not objects.

2
  • Which "native types" are you referring to? I've not run into anything in Python that's not an object.
    – Benson
    Mar 16, 2010 at 22:01
  • 1
    I stand corrected. From the Tutorial at DiveIntoPython.org: "2.4.2. What's an Object? Everything in Python is an object, and almost everything has attributes and methods." I was probably thinking of regular variables, which don't have any attributes by default. They are still objects. Yay Python.
    – Wexxor
    Mar 17, 2010 at 17:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.