Having programmed in Kawa for over a year now, and having programmed in Guile for some time before, I have some thoughts regarding #Java vs Common #Lisp.

I haven't used Java all that much, and Common Lisp even less, but I think that Guile's #GOOPS system is similar to #CLOS - and likewise, the OO system in Kawa literally is that of Java.

I remember the time when I was making set of GUI widgets for my humanoid robot pose editor. I was using GOOPS for that, and I feel that it was a total mess. Well, it did work, but I don't want to go back to that code.

I was using GOOPS in many other ways, for example - to overload various math operations for matrices and quaternions. The code I wrote back then can still be admired, say, here:

https://github.com/panicz/slayer/blob/master/guile-modules/extra/math.scm

I think it was today that I got enlightened on what I really didn't like about the GOOPS/CLOS approach with generic and multimethods. It may seem like extremely flexible system, but I think that multimethods combined with subclasses are a terrible idea in practice.

Suppose that we have a base class <A>

(define-class <A> ())
(define a (make <A>))

and its two subclasses:

(define-class <B> (<A>))
(define b (make <B>))

(define-class <C> (<A>))
(define c (make <C>))

Now, suppose that I also have a generic method:

(define-method (m (x <A>) (y <A>)) 'aa)

and its two specializations

(define-method (m (x <B>) (y <A>)) 'ba)

(define-method (m (x <A>) (y <C>)) 'ac)

Now, what is going to happen when I invoke

(m b c)

?

I checked it with Guile, and it chose the 'ba implementation. I don't know if that's because it was defined earlier, or because the method specialization is defined to be resolved from left to right - and frankly, I don't care.

Imagine that one programmer wrote the 'ac implementation and had some working code. Now, if another programmer comes and defines the 'ba variant, they would break the existing code. And this is the fundamental problem.

slayer/math.scm at master · panicz/slayer

Contribute to panicz/slayer development by creating an account on GitHub.

GitHub

Interestingly, Kawa co-evolved with Guile, and it attempted to provide a GOOPS-like interface to Java object system. And its manual contains the following remark:

"*Warning:* The current implementation of selecting the "best" method is not reliable if there is more than one method. It can select depending on argument count, and it can select between primitive Java methods. However, selecting between different Scheme procedures based on parameter types should be considered experimental. The main problem is we can’t determine the most specific method, so Kawa just tries the methods in order."

I think this is no accident - because in general there's literally no way to "choose the best method".

Now, what I like about Java is that it took the most important concept from the C language - namely - structures with function pointers - and elevated it to the notion of interface, which is probably the most foundational concept for software architecture.

Two things I don't like about Java are method overloading and the lack of mix-ins. But I like it that it didn't provide support for multiple inheritance.

Most importantly, though, Java taught me to think of objects as "things that have their identities and implement interfaces (and can be type-checked)"

Now, the GOOPS-inspired disguise for Java's object model is a bit weird, but fortunately Scheme has sublime support for syntax extensions, so that I could improve the notation a bit.

Anyway, what I wanted to achieve with all this writing was to irritate some Common Lisp fans by saying that Java's take on object-orientation is actually better than their beloved CLOS, which tries to be extremely general, but has a fundamental flaw in it.

Good night, everybody.

Take that, @jack !
@PaniczGodek I could take this more seriously if you actually used CLOS instead of deciding that an incomplete derived system would be able to give you a complete perspective. Also “structs of function pointers” *is* an interface in C…