Java does not support multiple inheritance. I understand that there is a hard problem to solve from a compiler / language point of view -- namely, the diamond problem -- but totally ignoring this language feature because of some problems ... that I can't understand. But the Scala language has this implemented (and it is based on Java) and it has it using a simple rule: right-first depth-first search of extended 'traits'.
While the same result can be achieved with interfaces and multiple inheritance of interfaces, this has some draw-backs:
- the fields are static and final in an interface
- non-abstract methods avoid code duplication
Why it made sense for me: I have two characteristics for a class -- one which determines the communication layer of this component (Sockets or WebSockets) and one which determines the functionality provided by this component (let's say binary). In total, I would actually need all 4 possible combinations. But, in this case, the code for sending a message via a Socket (or a WebSocket) does not change, regardless of the functionality. Also, the functionality does not depend in any way on the communication layer.
In this case, I would love to be able to inherit both classes that are useful for a certain combination and basically do nothing in the inherited class (see example). But it doesn't work :(
In terms of programming language, I have learned to love Scala -- I took some Logic classes that involved writing Scala code and it seems like a perfect blend of a functional programming language and a hidden interface to Java (in case you really need it). Unfortunately, even if the language is so good, the tools are extremely bad (or were the last time I used them, I see here some updates) -- the Eclipse IDE was extremely slow and on every save it would recompile the file and the system would just jam completely for 5 seconds, totally non-responsive.
It just seems you can't have best of all worlds: OS-independent code, a good language and a good IDE (though I have to look into the other IDEs for Scala).
Of course, someone else heard my cry for help regarding Scala and it seems that not much has changed: http://blog.empathybox.com/post/19126121307/scala-macros-oh-god-why
ReplyDelete