[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: the benefits of immutability



Perry E. Metzger wrote:
 > Then we should abandon object oriented programming.

Perhaps, we should.  I fail to see though how this follows from the
previous discussion though.

A well-reasoned opinion on this subject can be found in
http://www.dreamsongs.com/NewFiles/ObjectsHaveFailed.pdf

There was also a very good rebuttal by GLS at the same OOPSLA
conference, but I don't have a link handy.

 > In a language like Java, most of the point of object oriented
 > programming is subclassing.

That is open to debate.  Subtyping? Maybe.  Subclassing?  I really
don't think so.

 > Of course, most of Java doesn't just permit inheritance but indeed
 > depends on it -- see, for example, all the standard interfaces which
 > would be meaningless without inheritance because they would have no
 > implementations.

Good point.  Which brings us to the important distinction between
"type inheritance" and "implementation inheritance".  Implementing an
interface is type inheritance.  Extending a class is implementation
inheritance.  Writing an externally facing reusable class that allows
implementation inheritance is pretty *hard*.  Internally facing
classes are a whole different ball game, because the implementor
controls both the subclass and superclass, which makes subclassing
largely immune to problems that externally exported APIs have to deal
with.  Package-scoped classes that allow subclassing can be very handy
indeed.


 > If you seriously argue that forbidding subclassing of String has
 > something to do with the Liskov substitutability principle, then you
 > have some explaining to do about the entire rest of Java.

The entire rest of Java cannot be explained in one post. Nor am I up
to the task.  Perhaps, you could narrow it down a little bit?


 > Well, then, again, if inheritance is unsafe, why does the whole rest
 > of the language permit it and indeed depend on it?

See above.  Supporting implementation inheritance in a maintainable way
is hard.  Type inheritance is different.  See, for example, "Why
'extends' Is Evil":

http://www.javaworld.com/javaworld/jw-08-2003/jw-0801-toolbox.html


 > In any case, you could have the grace to admit your initial argument
 > which you've silently abandoned was incorrect.

I admit that my initial argument left much room for improvement.  So,
I'm changing it.  (For those with a modicum of interest in mathematics
and its history, "Proofs and Refutations" by Imre Lakatos is a fairly
short and very enjoyable account of how proofs evolve over time.
Might also be interesting to people who teach mathematics.)

Anyhow, I am starting to lose interest in this thread.  I hoped to
hear some good arguments against Java.  None have emerged thus far,
which I find rather surprising.  How about, we refine the "no function
pointers" argument into "no higher order functions" and proceed to
show the latter to also be less than entirely correct?